3
我在玩Rust和tiny-http。我已经创造了一种我与请求的报头搞乱,然后发送响应函数:因为借用而无法移出`req`
fn handle_request(req: Request) {
let headers = req.headers();
// working with headers
let res = Response::from_string("hi");
req.respond(res);
}
它失败,错误:
main.rs:41:5: 41:8 error: cannot move out of `req` because it is borrowed
main.rs:41 req.respond(res);
^~~
main.rs:27:19: 27:22 note: borrow of `req` occurs here
main.rs:27 let headers = req.headers();
^~~
error: aborting due to previous error
所以我有点明白req.headers()
接受&self
这执行借款req
和req.respond()
“移动”req
,因为它接受self
。我不确定我应该在这里做什么,有人能帮我理解吗?
还有http://doc.rust-lang.org/std/mem/fn.drop.html; ) – ArtemGr
这不会消除借贷,它只会降低价值。 –
@SteveKlabnik文档中的示例如何? '下降(mutable_borrow)'? – ArtemGr