From e7bcc933d67bde44aff09d96fb7ac57bd765638b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 31 Jul 2024 04:58:11 -0500 Subject: [PATCH] Add optional dependency on ordering crate Add an optional dependency on the `ordering` crate and implement `ArbitraryOrd` for `Fe32` if the feature is enabled. --- Cargo.toml | 3 +++ src/primitives/gf32.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 701ae225a..8e3109eab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,5 +19,8 @@ alloc = [] [target.'cfg(mutate)'.dev-dependencies] mutagen = { git = "https://github.com/llogiq/mutagen" } +[dependencies] +ordered = { version = "0.2.2", optional = true} + [lints.rust] unexpected_cfgs = { level = "deny", check-cfg = [ 'cfg(bench)', 'cfg(kani)', 'cfg(mutate)' ] } diff --git a/src/primitives/gf32.rs b/src/primitives/gf32.rs index 511a51252..9eb23fd02 100644 --- a/src/primitives/gf32.rs +++ b/src/primitives/gf32.rs @@ -256,6 +256,12 @@ impl AsRef for Fe32 { fn as_ref(&self) -> &u8 { &self.0 } } +/// Field elements do not have a natural order however some users may want to order them. +#[cfg(feature = "ordered")] +impl ordered::ArbitraryOrd for Fe32 { + fn arbitrary_cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.cmp(&other.0) } +} + impl super::Field for Fe32 { const ZERO: Self = Fe32::Q; const ONE: Self = Fe32::P;