Trait rkyv::ArchiveCopy[][src]

pub unsafe trait ArchiveCopy: Archive<Archived = Self> + Copy { }
Expand description

An Archive type that is a bitwise copy of itself and without additional processing.

Types that implement ArchiveCopy are not guaranteed to have a Serialize implementation 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::{
    archived_root,
    ser::{Serializer, serializers::AlignedSerializer},
    AlignedVec,
    Archive,
    Serialize,
};

#[derive(Archive, Serialize, Clone, Copy, Debug, PartialEq)]
#[archive(copy)]
struct Vector4<T>(T, T, T, T);

let mut serializer = AlignedSerializer::new(AlignedVec::new());
let value = Vector4(1f32, 2f32, 3f32, 4f32);
serializer.serialize_value(&value).expect("failed to archive Vector4");
let buf = serializer.into_inner();
let archived_value = unsafe { archived_root::<Vector4<f32>>(buf.as_ref()) };
assert_eq!(&value, archived_value);

Implementations on Foreign Types

Implementors