#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

#1092 in Encoding

Download history 747/week @ 2024-01-28 431/week @ 2024-02-04 54/week @ 2024-02-11 402/week @ 2024-02-18 582/week @ 2024-02-25 1073/week @ 2024-03-03 1154/week @ 2024-03-10 645/week @ 2024-03-17 1039/week @ 2024-03-24 587/week @ 2024-03-31 257/week @ 2024-04-07 825/week @ 2024-04-14 647/week @ 2024-04-21 97/week @ 2024-04-28 543/week @ 2024-05-05 567/week @ 2024-05-12

2,005 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

~295–750KB
~18K SLoC