使用显式生命周期时,Rocket 的状态错误 "Attempted to retrieve unmanaged state"?

Rocket's State errors with "Attempted to retrieve unmanaged state" when using an explicit lifetime?

当使用 Rocket 的 State 并省略生命周期时,可以正确处理对路由的请求:

#[post("/foo")]
pub fn foo_handler(db: State<Db>) {
    // ...
}

但是,如果提供了明确的生命周期,那么 Attempted to retrieve unmanaged state! 的请求会出现 Rocket 错误:

#[post("/foo")]
pub fn foo_handler<'a>(db: State<&'a Db>) {
    // ...
}

要么是编译器没有在此处选择某些东西,要么是 Rocket 避免了安全检查,因为这编译正常,没有任何错误或警告。有什么想法吗?

这似乎是实现所需结果的方法:

#[post("/foo")]
pub fn foo_handler<'a>(db: State<'a, Db>) {
  // ...
}

Rocket 的 State 文档中提供了一个示例。不过,我希望上述实现会抛出一个错误,因为它是有效的语法。

我发现此错误是由于未能调用 unwrap() 对我正在初始化以用于 State 的值造成的。

let index = load().unwrap(); // <-- without unwrap, compiled but failed on request
rocket::ignite()
  .manage(index) // normal mount and so on here
... etc ...