Rust 火箭';s用“s”表示错误;试图检索非托管状态“;当使用显式生存期时?
当使用Rocket的Rust 火箭';s用“s”表示错误;试图检索非托管状态“;当使用显式生存期时?,rust,rust-rocket,Rust,Rust Rocket,当使用Rocket的状态时,省略了生存期,则对路由的请求得到处理,ok: #[post("/foo")] pub fn foo_handler(db: State<Db>) { // ... } 这里要么是编译器没有注意到的东西,要么是Rocket避免了安全检查,因为这样编译正常,没有任何错误或警告。有什么想法吗?这似乎是实现所需结果的方法: #[post("/foo")] pub fn foo_handler<'a>(db: State<'a, Db&g
状态
时,省略了生存期,则对路由的请求得到处理,ok:
#[post("/foo")]
pub fn foo_handler(db: State<Db>) {
// ...
}
这里要么是编译器没有注意到的东西,要么是Rocket避免了安全检查,因为这样编译正常,没有任何错误或警告。有什么想法吗?这似乎是实现所需结果的方法:
#[post("/foo")]
pub fn foo_handler<'a>(db: State<'a, Db>) {
// ...
}
#[post(“/foo”)]
酒馆fn foo_handler){
// ...
}
一个例子在Rocket的文档中有所帮助。不过,我希望上述实现会抛出一个错误,因为它的语法是有效的。我发现此错误是由于未能调用
unwrap()
let index = load().unwrap(); // <-- without unwrap, compiled but failed on request
rocket::ignite()
.manage(index) // normal mount and so on here
... etc ...
let index=load().unwrap();//我认为这些签名不一样。db:statenop的作用仍然是相同的错误,编译时没有警告。
let index = load().unwrap(); // <-- without unwrap, compiled but failed on request
rocket::ignite()
.manage(index) // normal mount and so on here
... etc ...