nickel

Cannot borrow captured outer variable in an `Fn` closure as mutable

霸气de小男生 提交于 2019-12-05 12:25:16
问题 This is my first day with Rust, but I'm trying to do something trivial, and I'm stuck. What I'm trying to do is to add an struct to a Vector, and return the result. What I'm trying is to create a very simple REST service which will store the data in memory when posting, and return all the data in JSON format when doing a GET. This is my current code: fn main() { let mut server = Nickel::new(); let mut reservations = Vec::new(); server.post("/reservations/", middleware! { |request, response|

Cannot borrow captured outer variable in an `Fn` closure as mutable

╄→尐↘猪︶ㄣ 提交于 2019-12-03 23:37:33
This is my first day with Rust, but I'm trying to do something trivial, and I'm stuck. What I'm trying to do is to add an struct to a Vector, and return the result. What I'm trying is to create a very simple REST service which will store the data in memory when posting, and return all the data in JSON format when doing a GET. This is my current code: fn main() { let mut server = Nickel::new(); let mut reservations = Vec::new(); server.post("/reservations/", middleware! { |request, response| let reservation = request.json_as::<Reservation>().unwrap(); reservations.push(reservation); // <--

error: type parameter `D` must be used as the type parameter for some local type

百般思念 提交于 2019-11-30 09:23:32
问题 I'm using Nickel.rs with MongoDB to build a RESTful api. I'd like to implement a generic Responder for the type mongodb::error::Result<Option<bson::Document>> . This is the implementation I wrote based on the examples I found for Responder : impl<D> Responder<D> for Result<Option<Document>> { fn respond<'a>(self, mut response: Response<'a, D>) -> MiddlewareResult<'a, D> { response.set(MediaType::Json); match self { Ok(Some(doc))=>{ ApiResponse{data: Bson::Document(doc).to_json()}.to_json() },

error: type parameter `D` must be used as the type parameter for some local type

谁说我不能喝 提交于 2019-11-29 14:47:54
I'm using Nickel.rs with MongoDB to build a RESTful api. I'd like to implement a generic Responder for the type mongodb::error::Result<Option<bson::Document>> . This is the implementation I wrote based on the examples I found for Responder : impl<D> Responder<D> for Result<Option<Document>> { fn respond<'a>(self, mut response: Response<'a, D>) -> MiddlewareResult<'a, D> { response.set(MediaType::Json); match self { Ok(Some(doc))=>{ ApiResponse{data: Bson::Document(doc).to_json()}.to_json() }, Ok(None)=>{ response.set(StatusCode::NotFound); ApiError{error: "Not found".to_string()}.to_json() },