#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

#1771 in Encoding

Download history 4562/week @ 2024-07-28 2071/week @ 2024-08-04 2661/week @ 2024-08-11 3339/week @ 2024-08-18 4761/week @ 2024-08-25 3646/week @ 2024-09-01 1984/week @ 2024-09-08 628/week @ 2024-09-15 389/week @ 2024-09-22 159/week @ 2024-09-29 142/week @ 2024-10-06 62/week @ 2024-10-13 39/week @ 2024-10-20 76/week @ 2024-10-27 133/week @ 2024-11-03 76/week @ 2024-11-10

325 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

~235–680KB
~16K SLoC