I have some flatbuffers IDL:
table Filter {
text: string (required);
}
which generates the following .rs:
...
pub struct Filter<'a> {
pub _tab: flatbuffers::Table<'a>,
}
...
I'm trying to add some trait impl for it:
pub trait TFilter {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
...
impl TFilter for crate::schema_generated::Filter<'_> {
fn as_any(&self) -> &dyn Any { self }
fn as_any_mut(&mut self) -> &mut dyn Any { self }
}
I'm getting the following:
cannot infer an appropriate lifetime due to conflicting requirements
note: ...so that the type `schema_generated::Filter<'_>` will meet its required lifetime bounds
note: but, the lifetime must be valid for the static lifetime...
note: ...so that the expression is assignable
If i add lifetimes:
// flatbuffers-based impl
impl<'a> TFilter for crate::schema_generated::Filter<'a> {
fn as_any(&self) -> &'a dyn Any { self }
fn as_any_mut(&mut self) -> &'a mut dyn Any { self }
}
i'm getting the following:
the type `schema_generated::Filter<'a>` does not fulfill the required lifetime
note: type must satisfy the static lifetimerustc(E0477)
I'm not sure i understand that is meant.
If i understand correctly i need to mark as_any
living no longer than crate::schema_generated::Filter
, is it correct?
Any clue? Where did 'static
requirement come from?
PS. I've found the following, but i'm not sure if it's related.