rkyv_impl

Crates.iorkyv_impl
lib.rsrkyv_impl
version0.2.2
sourcesrc
created_at2023-08-01 21:11:27.382492
updated_at2023-08-03 05:17:57.66753
descriptionMacro for `rkyv` users to implement methods on `Foo` and `ArchivedFoo` in a single `impl` block.
homepagehttps://github.com/bonsairobo/rkyv_impl
repositoryhttps://github.com/bonsairobo/rkyv_impl
max_upload_size
id932213
size24,983
Duncan (bonsairobo)

documentation

README

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> {
    // Notice that the where clause is transformed so that
    // `T` is replaced with `T::Archived` in the generated `impl`.
    #[archive_method(transform_bounds(T))]
    fn sum<S>(&self) -> S
    where
        T: Clone,
        S: Sum<T>
    {
        self.elements.iter().cloned().sum()
    }
}

fn use_generated_method(foo: &ArchivedFoo<u32>) {
    // Call the generated method!
    let _ = foo.sum::<u32>();
}

License: MIT/Apache-2.0

Commit count: 33

cargo fmt