well, to be precise, it implements it for one type: `dyn Other`. &dyn Other, Box<dyn other> get it through deref, but they do not get the trait implemented
-
-
Replying to @ManishEarth @mountain_ghosts
Box<dyn Other> and &dyn Other are not T: Other, as I mentioned before. They get Other methods through deref. Some traits (eg. Fn*) may choose to blanket implement themselves on these types.
2 replies 0 retweets 0 likes -
Replying to @ManishEarth @mountain_ghosts
dyn Other is a single type. It's a virtually dispatched trait object, with a concrete value of *some* type implementing that trait behind it. It can only exist behind a pointer, because we don't know its size.
2 replies 0 retweets 0 likes -
-
Replying to @mountain_ghosts @ManishEarth
Yes. It points to a vtable with the size information and function pointers to all the trait methods
1 reply 0 retweets 0 likes -
Replying to @sgrif @ManishEarth
but a `dyn Trait` cannot exist as a value on its own? it needs a wrapper type to implement a pointer to the concrete value?
1 reply 0 retweets 1 like -
Replying to @mountain_ghosts @ManishEarth
Correct. Something has to actually point to that vtable and size information.
1 reply 0 retweets 1 like -
Replying to @sgrif @ManishEarth
the thing I wasn't getting is that I was thinking about dynamic OO languages, where the class/vtable pointer is part of the value whereas here you have a pair of pointers, one to the value and one to the vtable that's relevant at that call site, it's contextual
1 reply 0 retweets 1 like -
Replying to @mountain_ghosts @ManishEarth
I think that distinction is really just an implementation detail. It could have easily been implemented as `*mut (*const Vtable, Data)` and the semantics would still be the same
2 replies 0 retweets 2 likes -
Replying to @sgrif @mountain_ghosts
not really, arbitrary pointer types wouldn't be able to wrap this the same way then (right now Arc<T> casts to Arc<dyn Trait>) Unless you do double indirection, in which case dyn Trait is basically just Box<dyn Trait> everywhere, including in borrows (ew)
2 replies 0 retweets 1 like
Right, that's what I mean. We could have done double indirection. We didn't for perf reasons. It doesn't change the semantics meaningfully though (I'm assuming most folks aren't doing things that care about the size of a pointer)
-
-
Replying to @sgrif @mountain_ghosts
It does, you wouldn't be able to take a stack reference and cast it to &dyn trait and have that be compatible with a reference obtained from a Box<dyn Trait>, the ownership semantics change too
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.