[−][src]Macro mopa::mopafy
The macro for implementing all the Any
methods on your own trait.
Instructions for use
-
Make sure your trait extends
mopa::Any
(e.g.trait Trait: mopa::Any { }
) -
Mopafy your trait (see the next subsection for specifics).
-
…
-
Profit!
Mopafication techniques
There are three ways of mopafying traits, depending on what libraries you are using.
-
If you are a normal person:
trait Trait: mopa::Any { } mopafy!(Trait);
-
If you are using libcore but not libstd (
#![no_std]
) or liballoc, enable theno_std
Cargo feature and write this:ⓘThis example is not testedmopafy!(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; theBox<Any>
methods require liballoc. -
If you are using libcore and liballoc but not libstd (
#![no_std]
), enable theno_std
Cargo feature and write this:ⓘThis example is not testedmopafy!(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.