mopa
My Own Personal Any: add Any-style downcasting methods to your own Rust traits.
Repository Health
Technical Analysis
mopa (My Own Personal Any) is a Rust library that lets you glue the functionality of std::any::Any onto your own trait objects. By making mopa::Any a supertrait and invoking the mopafy! macro, your trait gains is, downcast_ref, downcast_mut, and downcast methods, so you can store heterogeneous values behind your trait and recover their concrete types.
What You Get
- A mopafy! macro that implements Any downcasting on your trait
- is, downcast_ref, downcast_mut, and downcast methods on your trait objects
- A mopa::Any supertrait to bridge custom traits with std::any::Any
- Support for no_std usage through feature configuration
Common Use Cases
- Downcasting custom trait objects back to their concrete types
- Building plugin or component systems with heterogeneous trait objects
- Storing mixed types behind a shared domain trait and recovering them
Under The Hood
Architecture
The library is a single lib.rs exposing the mopa::Any supertrait and the mopafy! declarative macro. mopafy! expands to trait implementations that delegate to std::any::Any’s TypeId machinery, generating is, downcast_ref, downcast_mut, and downcast methods so your trait object can perform checked casts back to concrete types.
Tech Stack
Pure Rust with no runtime dependencies; the functionality is delivered entirely through a macro_rules-style macro and trait definitions. A no_std_examples feature demonstrates usage outside the standard library.
Code Quality
The crate is small, stable, and dependency-free, with clear documentation adapted from the original crate docs. It is a long-standing utility (the maintained republish continues an older design), so the API is conservative and well understood, though it predates newer downcasting idioms in the ecosystem.
API Design
Adoption is three steps: import the macro, make mopa::Any a supertrait, and call mopafy!(YourTrait). After that, trait objects expose the same downcasting API as std::any::Any, which is familiar to most Rust developers and keeps the learning curve low.