monomo

Crates.iomonomo
lib.rsmonomo
version0.1.3
sourcesrc
created_at2022-02-11 22:36:48.698078
updated_at2022-02-28 21:42:38.440669
descriptionExplicit trait monomorphization
homepage
repositoryhttps://github.com/zylkowski/monomo
max_upload_size
id531073
size1,498
zylkowski_a (zylkowski)

documentation

README

monomo

Easy trait monomoprhization crate. Especially useful with typetag crate.

Example

Suppose we have a trait Foo<T> and we would like to monomorphize it in order to use it with typetag, as we cannot use generic trait.

trait Foo<T> {}

// Notice that you don't have to use typetag attribute, 
// and the trait will still be monomorphized. 
// typetag is just good example when you would like to use monomo.
monomo::rphize!(
    #[typetag::serde]
    Foo<i32>
);

Above macro expands to monomorphized version of Foo<i32>.

In order to implement monomorphized trait for a struct we can do the following:

// Notice that you don't have to use typetag attribute, 
// and the trait will still be monomorphized. 
// typetag is just good example when you would like to use monomo.
#[monomo::rphize_impl]
#[typetage::serde]
impl Foo<i32> for Bar {
    // ...
}

Thanks to this you can later use Foo<i32> implementors as the monomorphized trait object.

struct BarContainer {
    bars: Vec<monomo::rph!(Foo<i32>)>
}
Commit count: 12

cargo fmt