| Crates.io | monomo |
| lib.rs | monomo |
| version | 0.1.3 |
| created_at | 2022-02-11 22:36:48.698078+00 |
| updated_at | 2022-02-28 21:42:38.440669+00 |
| description | Explicit trait monomorphization |
| homepage | |
| repository | https://github.com/zylkowski/monomo |
| max_upload_size | |
| id | 531073 |
| size | 1,498 |
Easy trait monomoprhization crate. Especially useful with typetag crate.
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>)>
}