#rkyv #impl-block #macro #foo #archive #methods #archived-foo

macro rkyv_impl

Macro for rkyv users to implement methods on Foo and ArchivedFoo in a single impl block

4 releases

0.2.2 Aug 3, 2023
0.2.1 Aug 3, 2023
0.2.0 Aug 2, 2023
0.1.0 Aug 1, 2023

#1160 in Encoding

Download history 691/week @ 2024-03-14 584/week @ 2024-03-21 960/week @ 2024-03-28 374/week @ 2024-04-04 548/week @ 2024-04-11 969/week @ 2024-04-18 61/week @ 2024-04-25 422/week @ 2024-05-02 345/week @ 2024-05-09 569/week @ 2024-05-16 483/week @ 2024-05-23 1285/week @ 2024-05-30 771/week @ 2024-06-06 929/week @ 2024-06-13 211/week @ 2024-06-20 635/week @ 2024-06-27

2,851 downloads per month

MIT/Apache

24KB
532 lines

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


lib.rs:

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

Dependencies

~285–740KB
~18K SLoC