[−][src]Derive Macro rkyv::Archive
#[derive(Archive)] { // Attributes available to this derive: #[archive] #[recursive] }
Derives Archive
for the labeled type.
Additional arguments can be specified using the #[archive(...)]
attribute:
copy
: ImplementsArchiveCopy
as well asArchive
. Only suitable for types that can be directly archived.derive(...)
: Adds a#[derive(...)]
attribute to the archived type.name
,name = "..."
: Exposes the archived type with the given name. If used without a name assignment, uses the name"Archived" + name
.
This derive macro automatically adds a type bound field: Archive
for each
field type. This can cause an overflow while evaluating trait bounds if the
structure eventually references its own type, as the implementation of
Archive
for a struct depends on each field type implementing it as well.
Adding the attribute #[recursive]
to a field will suppress this trait
bound and allow recursive structures. This may be too coarse for some types,
in which case Archive
will have to be implemented manually.
Example
use rkyv::Archive; #[derive(Archive)] enum Node<T> { Nil, Cons(T, #[recursive] Box<Node<T>>), }