[−][src]Trait rkyv::ArchiveSelf
A trait that indicates that some Archive
type can be copied directly to
an archive without additional processing.
You can derive an implementation of ArchiveSelf
by adding
#[archive(self)]
to the struct or enum. Types that implement ArchiveSelf
must also implement Copy
.
Types that implement ArchiveSelf
are not guaranteed to have archive
called on them to archive their value. Most or all implementations that
leverage ArchiveSelf
will require the specialization
feature.
ArchiveSelf
must be manually implemented even if a type implements
Archive
and Copy
because some types may
transform their data when writing to an archive.
Examples
use rkyv::{Aligned, Archive, ArchiveBuffer, archived_value, Write, WriteExt}; #[derive(Archive, Clone, Copy, Debug, PartialEq)] #[archive(self)] struct Vector4<T>(T, T, T, T); let mut writer = ArchiveBuffer::new(Aligned([0u8; 256])); let value = Vector4(1f32, 2f32, 3f32, 4f32); let pos = writer.archive(&value) .expect("failed to archive Vector4"); let buf = writer.into_inner(); let archived_value = unsafe { archived_value::<Vector4<f32>>(buf.as_ref(), pos) }; assert_eq!(&value, archived_value);