3 ms·
Because rust is statically typed, and "x" has to have a concrete type known at compile time? Maybe there's a use case for matching trait objects against types
by elihu 10y ago
Because rust is statically typed, and "x" has to have a concrete type known at compile time?
Maybe there's a use case for matching trait objects against types to get back the original type. But, I think you could do the same thing by adding a trait method that returns Option<T> for some desired type T. If the object wasn't that type, it could just return None.
- tatterdemalion 10y agoAnd this is actually implemented by the Any trait. https://doc.rust-lang.org/std/any/trait.Any.html https://doc.rust-lang.org/std/any/trait.Any.html
- Manishearth 10y agohttps://doc.rust-lang.org/std/any/trait.Any.html#method.downcast_ref https://doc.rust-lang.org/std/any/trait.Any.html#method.down... ? :)