Skip to content

zylkowski/monomo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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>)>
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages