This thread is a follow-up question to an answer from @Yandros in this other (now closed) thread: Box with a trait object requires static lifetime? - #2 by Yandros
His code is here:
struct Holder<'lifetime> {
objects: Vec<Box<dyn Object + 'lifetime>>,
}
impl<'lifetime> Holder<'lifetime> {
fn add_object<T : Object + 'lifetime> (
self: &'_ mut Self,
object: T,
)
{
self.objects
.push(Box::new(object))
;
}
}
But when I change Object
to std::any::Any
, now the compiler isn't cool about the lifetimes anymore.
So, having no idea what the Object
trait is, I figured I'd try implementing it. But I can't seem to figure out what methods it requires and the compiler usually tells me, but not this time.
I found lots of documentation about "trait objects", but the only thing I found about the "Object trait" was this: object::Object - Rust, and compiled machine code, aka "binary objects" and the "object files" that store them, are definitely unrelated.
My core question is how to make it so I can box up bounded lifetimes, but this "Object trait" red herring has me really confused.
Thanks in advance for any replies. I'm sure I'll be smacking my forehead really hard when I hear what I'm doing wrong.