Skip to content

Commit

Permalink
Add optional dependency on ordering crate
Browse files Browse the repository at this point in the history
Add an optional dependency on the `ordering` crate and implement
`ArbitraryOrd` for `Fe32` if the feature is enabled.
  • Loading branch information
tcharding committed Jul 31, 2024
1 parent eb49666 commit 0e9d4e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)' ] }
6 changes: 6 additions & 0 deletions src/primitives/gf32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ impl AsRef<u8> 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;
Expand Down

0 comments on commit 0e9d4e7

Please sign in to comment.