Is it possible to add new methods to a trait from an external crate?

When downcasting in Rust, you (attempt to) downcast to the erased type. In that snippet, you would only be able to successfully downcast to a TabBar.

You can switch between dyn Trait types like so. But I'm not sure this actually accomplishes anything you're trying to do.


As for why Rc::downcast is called that way, it's due to its smart-pointer nature:

The inherent methods of Rc are all associated functions, which means that you have to call them as e.g., Rc::get_mut(&mut value) instead of value.get_mut(). This avoids conflicts with methods of the inner type T.

1 Like