My code:
fn request_add<T>(request: &mut Request, collection_name: &'static str) -> Fallible<Fallible<String>>
where
T: serde::Serialize + serde::de::DeserializeOwned,
{
let add_dao = dao::MongoDao::new(collection_name);
let obj = serde_json::from_reader::<Body, T>(request.body)?; //cannot move out of borrowed content
Ok(add_dao.add(&obj))
}
I have a cannot move out of borrowed content
error, because request
is a reference, but why does serde_json::from_reader
not use a mut reference? Why does it need ownership? And how can I fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…