Hasty Briefsbeta

Bilingual

Rust Any part 3: we have upcasts

a year ago
  • #TypeCasting
  • #Programming
  • #Rust
  • The As-Any Hack was introduced three years ago to enable upcasting to supertraits in stable Rust.
  • The hack addressed the issue where methods from the `Any` trait couldn't be used on a `dyn DebugAny`, despite `DebugAny` inheriting from `Any`.
  • As of Rust 1.86, the issue is fixed, allowing direct use of `Any` methods like `downcast_ref` on `dyn DebugAny`.
  • The fix means old workarounds like the As-Any Hack can be retired once the minimum supported Rust version (MSRV) is updated.
  • An updated example of the `Extensions` struct demonstrates how to use the new functionality without the hack.