I want to work with several Vec
at once. These vectors can be specialized with different types. I created a trait:
trait Column {
//fn insert
//fn remove
}
impl<T> Column for Vec<T> // ...
I can convert Vec<T1>
and Vec<T2>
to Box<Column>
, but I also need to convert Box<Column>
back to Vec
. As suggested in How to get a struct reference from a boxed trait?, I wrote:
use std::any::Any;
trait Column {
fn as_any(&self) -> &Any;
}
impl<T> Column for Vec<T>
where T: Default
{
fn as_any(&self) -> &Any {
self //ERROR!
}
}
but this code generates an error:
error[E0310]: the parameter type `T` may not live long enough
--> src/main.rs:11:9
|
11 | self //ERROR!
| ^^^^
|
= help: consider adding an explicit lifetime bound `T: 'static`...
note: ...so that the type `std::vec::Vec<T>` will meet its required lifetime bounds
--> src/main.rs:11:9
|
11 | self //ERROR!
| ^^^^
How can I fix this issue?