Skip to content

Attribute macro for implementing methods on both Foo and ArchivedFoo.

Notifications You must be signed in to change notification settings

bonsairobo/rkyv_impl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rkyv_impl

Crates.io Docs.rs

Implement methods for Foo and ArchivedFoo in a single impl block.

use rkyv::Archive;
use rkyv_impl::*;
use std::iter::Sum;

#[derive(Archive)]
struct Foo<T> {
    elements: Vec<T>
}

#[archive_impl(transform_bounds(T))]
impl<T> Foo<T> {
    #[archive_method(transform_bounds(T))]
    fn sum<S>(&self) -> S
    where
        T: Clone,
        S: Sum<T>
    {
        self.elements.iter().cloned().sum()
    }
}

// Notice that the trait bounds are transformed so that
// `T` is replaced with `T::Archived`.
fn call_generated_method<T, S>(foo: &ArchivedFoo<T>)
where
    T: Archive,
    T::Archived: Clone,
    S: Sum<T::Archived>
{
    let _ = foo.sum::<S>();
}

License: MIT/Apache-2.0

About

Attribute macro for implementing methods on both Foo and ArchivedFoo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages