'cannot move out of a shared reference' #1063
-
I am trying to write the following function: async fn new_enforcer(
&self,
mut i:Request<casbin_proto::NewEnforcerRequest>,
) -> Result<Response<casbin_proto::NewEnforcerReply>, Status> {
// implement TryIntoMethod for following a as well
let mut a: Option<Box<dyn Adapter>> = None;
let e: Enforcer;
if i.get_mut().adapter_handle != -1 {
a = match self.get_adapter(i.into_inner().adapter_handle) {
Ok(&v) => Some(v),
Err(er) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
}
if i.get_mut().model_text == String::from("") {
let cfg = adapter::load_configuration("config/connection_config.json").await?;
let data = match std::fs::read_to_string(cfg.enforcer.as_str()) {
Ok(v) => v,
Err(er) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
}
if a.is_none() {
let m = match DefaultModel::from_str(i.get_mut().model_text.as_str()).await {
Ok(v) => v,
Err(e) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
e = match casbin::Enforcer::new(m, ()).await {
Ok(v) => v,
Err(er) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
} else {
let m = match DefaultModel::from_str(i.get_mut().model_text.as_str()).await {
Ok(v) => v,
Err(er) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
e = match casbin::Enforcer::new(m, a).await {
Ok(v) => v,
Err(er) => return Ok(Response::new(casbin_proto::NewEnforcerReply { handler: 0 })),
};
}
let h = self.add_enforcer(e);
Ok(Response::new(casbin_proto::NewEnforcerReply { handler: h }))
} Here request is: tonic::request
pub struct Request<T> Here I get the following error: For the similar errors, generally My Cargo.toml has following version of tonic and prost: tonic = "0.8.0"
prost = "0.11.0"
bytes = "1.2.1" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You must updated your get_adapter method to take references and not ownership. I recommend this chapter of the book https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html |
Beta Was this translation helpful? Give feedback.
You must updated your get_adapter method to take references and not ownership. I recommend this chapter of the book https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html