[−][src]Trait rkyv::ArchiveCopy
A trait that indicates that some Archive
type can be copied directly to
an archive without additional processing.
Types that implement ArchiveCopy
are not guaranteed to have archive
called on them to archive their value.
You can derive an implementation of ArchiveCopy
by adding
#[archive(copy)]
to the struct or enum. Types that implement ArchiveCopy
must also implement Copy
.
ArchiveCopy
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}; #[derive(Archive, Clone, Copy, Debug, PartialEq)] #[archive(copy)] 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);