I have a function that returns a reference to a trait (trait_ref()
) and another function that takes a reference to a generic trait implementation (take_trait_ref_generic
).
However, it's not possible to pass the reference I get from the first function to the second one. Rustc complains that "the trait std::marker::Sized
is not implemented for SomeTrait
".
Even though that's true, why does it have to implement Sized
? It's a reference anyway.
trait SomeTrait {}
struct TraitImpl;
impl SomeTrait for TraitImpl {}
struct Container {
trait_impl: TraitImpl,
}
impl Container {
fn trait_ref(&self) -> &SomeTrait {
&self.trait_impl
}
}
fn take_trait_ref_generic<T: SomeTrait>(generic_trait_ref: &T) {}
fn main() {
let container = Container { trait_impl: TraitImpl };
/*Not possible*/
take_trait_ref_generic(container.trait_ref());
}