I want to create a new Context
object and then return it if it works. However, Rust says that &context
does not live long enough.
How can I force context
to live as long as Bo
in this case? Is it not enough to use the lifetime parameter b
in the definition of the return type?
impl<'b> Bo {
pub fn new() -> Result<&'b Context, BoError> {
match Context::new() {
Ok(context) => {
return Ok(&context);
}
Err(e) => Err(BoError {}),
}
}
}