我想创建一个新的Context
对象,如果有效,则返回它。但是,Rust说&context
的寿命不够长。
在这种情况下,我如何强制context
生效Bo
?在返回类型的定义中使用生命周期参数b
是不够的?
impl<'b> Bo {
pub fn new() -> Result<&'b Context, BoError> {
match Context::new() {
Ok(context) => {
return Ok(&context);
}
Err(e) => Err(BoError {}),
}
}
}