actix-web - 没有为 `CasbinActor 实现特征`Actor``
问题描述
error[E0277]: the trait bound `CasbinActor<CachedEnforcer>: Actor` is not satisfied
--> actix-middleware-example/src/api/user.rs:34:12
|
34 | actor: web::Data<Addr<CasbinActor<CachedEnforcer>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Actor` is not implemented for `CasbinActor<CachedEnforcer>`
|
::: /home/samarpan/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.11.1/src/address/mod.rs:77:20
|
77 | pub struct Addr<A: Actor> {
| ----- required by this bound in `Addr`
error[E0277]: the trait bound `CasbinActor<CachedEnforcer>: Actor` is not satisfied
--> actix-middleware-example/src/services/account_service.rs:24:12
|
24 | actor: web::Data<Addr<CasbinActor<CachedEnforcer>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Actor` is not implemented for `CasbinActor<CachedEnforcer>`
|
::: /home/samarpan/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.11.1/src/address/mod.rs:77:20
|
77 | pub struct Addr<A: Actor> {
| ----- required by this bound in `Addr`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
error: could not compile `actix-middleware-example`
To learn more, run the command again with --verbose.
这是我运行时的错误cargo build
。
Actor trait 是为 CasbinActor 实现的。
pub struct CasbinActor<T: IEnforcer + 'static> {
pub enforcer: Option<Arc<RwLock<T>>>,
}
impl<T: IEnforcer + 'static> CasbinActor<T> {
pub async fn new<M: TryIntoModel, A: TryIntoAdapter>(
m: M,
a: A,
) -> Result<Addr<CasbinActor<T>>> {
let enforcer = T::new(m, a).await?;
Ok(Supervisor::start(|_| CasbinActor {
enforcer: Some(Arc::new(RwLock::new(enforcer))),
}))
}
pub fn set_enforcer(e: Arc<RwLock<T>>) -> Result<CasbinActor<T>> {
Ok(CasbinActor { enforcer: Some(e) })
}
pub fn get_enforcer(&mut self) -> Option<Arc<RwLock<T>>> {
self.enforcer.as_ref().map(|x| Arc::clone(x))
}
}
impl<T: IEnforcer + 'static> Actor for CasbinActor<T> {
type Context = Context<Self>;
}
解决方法是什么?我认为问题可能是因为 CasbinActor在isActor
时实现了一个特征。也许必须做类似的事情,但我究竟在哪里添加代码来解决这个问题?T
IEnforcer
CachedEnforcer
这是回购 - https://github.com/casbin-rs/examples/tree/master/actix-middleware-example
解决方案
推荐阅读
- vb.net - 如何在 VB .net 中左右修剪字符串
- android - 无法在 android 中查看 RecyclerView 上的数据
- java - 带有依赖项的jar spring boot gradle
- sql - 将一个表中的行分配给其他表中的行,这些行在 SQL oracle 中具有相同数量的行的状态
- c# - Unity3D如何停止下拉重复添加?
- javascript - 无法在 JavaScript 中访问 DevExpress ASPxDateEdit
- laravel - 类似于 Yii 的 Laravel 路由模式
- ruby - 将对象推入循环内的哈希中
- mysql - Loopback 3 当前日期时间
- python - 代码没有选择负数而是返回 0,我该如何修复我的代码?