Skip to content

Commit

Permalink
Implement Hash for ByteOrder types (#1872)
Browse files Browse the repository at this point in the history
The absence of these impls lead to the absence of `Hash` for the
byteorder-aware numeric types.

Release 0.8.5.

Fixes #1871
  • Loading branch information
jswrenn authored Oct 11, 2024
1 parent 246bd90 commit d42e46f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[package]
edition = "2021"
name = "zerocopy"
version = "0.8.4"
version = "0.8.5"
authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
categories = ["embedded", "encoding", "no-std::no-alloc", "parsing", "rust-patterns"]
Expand Down Expand Up @@ -77,13 +77,13 @@ std = ["alloc"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd", "std"]

[dependencies]
zerocopy-derive = { version = "=0.8.4", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.4", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }

[dev-dependencies]
itertools = "0.11"
Expand All @@ -97,6 +97,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.4", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
9 changes: 5 additions & 4 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use core::{
convert::{TryFrom, TryInto},
fmt::{Binary, Debug, LowerHex, Octal, UpperHex},
hash::Hash,
num::TryFromIntError,
};

Expand All @@ -81,7 +82,7 @@ use super::*;
///
/// [`U32<BigEndian>`]: U32
pub trait ByteOrder:
Copy + Clone + Debug + Display + Eq + PartialEq + Ord + PartialOrd + private::Sealed
Copy + Clone + Debug + Display + Eq + PartialEq + Ord + PartialOrd + Hash + private::Sealed
{
#[doc(hidden)]
const ORDER: Order;
Expand All @@ -104,7 +105,7 @@ pub enum Order {
/// Big-endian byte order.
///
/// See [`ByteOrder`] for more details.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum BigEndian {}

impl ByteOrder for BigEndian {
Expand All @@ -121,7 +122,7 @@ impl Display for BigEndian {
/// Little-endian byte order.
///
/// See [`ByteOrder`] for more details.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum LittleEndian {}

impl ByteOrder for LittleEndian {
Expand Down Expand Up @@ -1070,7 +1071,7 @@ mod tests {
}

trait ByteOrderType:
FromBytes + IntoBytes + Unaligned + Copy + Eq + Debug + From<Self::Native>
FromBytes + IntoBytes + Unaligned + Copy + Eq + Debug + Hash + From<Self::Native>
{
type Native: Native;
type ByteArray: ByteArray;
Expand Down
2 changes: 1 addition & 1 deletion zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[package]
edition = "2021"
name = "zerocopy-derive"
version = "0.8.4"
version = "0.8.5"
authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Custom derive for traits from the zerocopy crate"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
Expand Down

0 comments on commit d42e46f

Please sign in to comment.