mopa

My Own Personal Any: add Any-style downcasting methods to your own Rust traits.

Library
Cargo
v0.2.3
118stars
Custom / Unknown

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
28/100Needs Attention
Development Activity0
Maintenance0
Community40
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture68
Code Quality70
Innovation66
Learning Curve72

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search