Skip to main content

OrdRepr

Derive Macro OrdRepr 

Source
#[derive(OrdRepr)]
Expand description

Derives OrdRepr for the rkyv archived form of a struct or enum, so that ArchivedFoo can be ordered against a Foo without deserializing. It applies to types whose archived form comes from #[derive(Archive)], and therefore is named ArchivedFoo and mirrors Foo’s fields.

The generated comparison follows #[derive(Ord)]: struct fields compare in declaration order, and enum variants compare by declaration position before their payloads. It therefore agrees with Ord on the original whenever Ord is derived. A type with a hand-written Ord must hand-write OrdRepr to match it, and so must an enum with an explicit discriminant, which #[derive(Ord)] orders by discriminant value rather than by position; the derive rejects such an enum.

Every field type T gets the bound <T as Archive>::Archived: OrdRepr<T>, in the same way that rkyv’s derive bounds field types. A field marked #[omit_bounds] (rkyv’s attribute for recursive fields) contributes no bound, which is what keeps a recursive type from requiring itself.