Создание минимального MCVE почти всегда облегчает задачу:
extern crate actix;
extern crate actix_web;
use actix::prelude::*;
use actix_web::dev::Handler;
use std::io;
pub struct MysqlConnection;
impl Actor for MysqlConnection {
type Context = SyncContext<Self>;
}
pub struct DummyMessage;
impl Message for DummyMessage {
type Result = io::Result<String>;
}
impl Handler<DummyMessage> for MysqlConnection {
type Result = io::Result<String>;
fn handle(&mut self, _: DummyMessage, _: &mut Self::Context) -> Self::Result {
unimplemented!();
}
}
fn main() {}
error[E0220]: associated type `Context` not found for `Self`
--> src/main.rs:22:53
|
22 | fn handle(&mut self, _: DummyMessage, _: &mut Self::Context) -> Self::Result {
| ^^^^^^^^^^^^^ associated type `Context` not found
Проблема 1 - несколько версий
actix-web = "0.6.14"
actix = "0.6.1"
Это приводит к двум различным версиям actix:
$ cargo tree -d
actix v0.5.8
└── actix-web v0.6.14
└── repro v0.1.0 (file:///private/tmp/repro)
actix v0.6.1
└── repro v0.1.0 (file:///private/tmp/repro)
Выберите один, actix 0.5.8.
Смотри также:
Задача 2 - неправильная черта
Вы вносите actix_web::dev::Handler
:
pub trait Handler<S>: 'static {
type Result: Responder;
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result;
}
Вы реализуете actix::Handler
:
pub trait Handler<M>
where
Self: Actor,
M: Message,
{
type Result: MessageResponse<Self, M>;
fn handle(&mut self, msg: M, ctx: &mut Self::Context) -> Self::Result;
}
actix::Handler
имеет Actor
в качестве супертрейта, что означает, что он может получить доступ к связанному типу Context
. actix_web::dev::Handler
не имеет супертрейта, поэтому он не знает о Self::Context
.
Выберите подходящую черту и правильно ее реализуйте.