3 ms·
Interesting to see the Wake trait introduced. It appears to make it possible to create a Waker implementation without requiring unsafe code, at the cost of requ
by jkarneges 6y ago
Interesting to see the Wake trait introduced. It appears to make it possible to create a Waker implementation without requiring unsafe code, at the cost of requiring the use of Arc.
The way the trait is used by the standard library is amusing. A trait bound is used to ensure a valid implementation is provided, but then the trait wrapping is thrown away and the inner value is only kept around as a raw pointer. That pointer is then casted back to the trait when a method needs to be invoked on it. I guess this works because the methods use Arc<Self> as self. The trait implementation basically carries its own boxed data with itself, so whoever "owns" the trait implementation doesn't have to worry about managing a dynamically sized value. Has anyone seen that pattern used anywhere else?