Skip to main content

Crate assert_order

Crate assert_order 

Source
Expand description

§assert-order

Assert the definition order of enum variants.

§Why?

The main motivation is that plenty of serialization formats are not self-describing, which means that for enums, in particular, reordering enum variants can result in de/serialization errors.

This crate allows you to assert the order of enum variants, which can help prevent accidental reordering.

§Example

use assert_order::{VariantOrder, assert_order};

#[derive(VariantOrder)]
enum TestEnum {
    A,
    B(),
    C {},
}

assert_order::<TestEnum, _, _>(["A", "B", "C"]);

Traits§

VariantOrder
Trait for getting the canonical ordering of an enum’s variants.

Functions§

assert_order
Assert the ordering of some enum implementing VariantOrder.

Derive Macros§

VariantOrder
Derive macro for implementing VariantOrder based on the definition of an enum.