Macro mopa::mopafy[][src]

macro_rules! mopafy {
    ($trait_:ident) => { ... };
    ($trait_:ident, core = $core:ident) => { ... };
    ($trait_:ident, core = $core:ident, alloc = $alloc:ident) => { ... };
}

The macro for implementing all the Any methods on your own trait.

Instructions for use

  1. Make sure your trait extends mopa::Any (e.g. trait Trait: mopa::Any { })

  2. Mopafy your trait (see the next subsection for specifics).

  3. Profit!

Mopafication techniques

There are three ways of mopafying traits, depending on what libraries you are using.

  1. If you are a normal person:

    trait Trait: mopa::Any { }
    mopafy!(Trait);
  2. If you are using libcore but not libstd (#![no_std]) or liballoc, enable the no_std Cargo feature and write this:

    mopafy!(Trait, core = core);

    (This is akin to mopafy!(Trait, core = std) if you were using libstd.)

    Unlike the other two techniques, this only gets you the &Any and &mut Any methods; the Box<Any> methods require liballoc.

  3. If you are using libcore and liballoc but not libstd (#![no_std]), enable the no_std Cargo feature and write this:

    mopafy!(Trait, core = core, alloc = alloc);

    (This is akin to mopafy!(Trait, core = std, alloc = std) if you were using libstd; in fact, the first form is just sugar for this very thing.)

    This gets you all the methods.