4 个版本
| 0.2.2 | 2023年8月3日 |
|---|---|
| 0.2.1 | 2023年8月3日 |
| 0.2.0 | 2023年8月2日 |
| 0.1.0 | 2023年8月1日 |
#1160 在 编码
2,851 每月下载量
24KB
532 行
rkyv_impl
在一个 impl 块中实现 Foo 和 ArchivedFoo 的方法。
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>();
}
许可证:MIT/Apache-2.0
lib.rs:
在一个 impl 块中实现 Foo 和 ArchivedFoo 的方法。
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>();
}
依赖项
~285–740KB
~18K SLoC