Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Borrowing as Any non-'static
I am doing something quite straightforward. Just trying to get a ref to a struct after it was passed around as a trait in a Box. The usual help on as_any
does not apply, because the lifetimes are not static. According to the searches I have made, one should first convert to Any, with some borrowing and then downcast. This almost works, but Rust gets insistent about 'static
-ness.
One solution would be the following function. But how do I write it? Rust error suggestions are circular, as often is the case. (The lifetime on the reference, 'a
, is perhaps not needed, but everything is annotated for debugging.)
pub fn z_to_a<'a, 'b>(input: &'a mut (dyn SomeTrait + 'b)) -> &'a mut (dyn Any + 'b)
where
'a: 'b,
{
// Implementation here.
}
3 posts - 3 participants
🏷️ rust_feed