Using &self as &Trait from a default trait function implementation
Is there a way to have a default implementation of a trait reference itself as a reference to a trait? Here is a play.rust-lang.org link of what I'd like. Is there a better way to do something like this?
Thanks.
Posted Aug 3, 2016, 6:54 PM UTC
26
Not sure if that's what you want, but:
Hmm, that at least compiles for unused code case, but if I have a
&T, I can call neithertnorssince I don't know aSizedtype for the trait to match the bounds.New gist.
Here's a version with generic types, instead of storing trait objects: https://is.gd/owwRrc.
I don't know if this is the best way to do it, but it works so that's something!
Yeah, that'd work, but the struct being parameterized like that isn't so nice. The u/Gustom approach posted is probably the best way.
[deleted]