From d42e46fa1d41ba6e762308e2395853ed4ad00f17 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Fri, 11 Oct 2024 13:59:07 -0400 Subject: [PATCH] Implement `Hash` for `ByteOrder` types (#1872) The absence of these impls lead to the absence of `Hash` for the byteorder-aware numeric types. Release 0.8.5. Fixes #1871 --- Cargo.toml | 8 ++++---- src/byteorder.rs | 9 +++++---- zerocopy-derive/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab90dcebd7..f420b7dc9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ [package] edition = "2021" name = "zerocopy" -version = "0.8.4" +version = "0.8.5" authors = ["Joshua Liebow-Feeser "] 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"] @@ -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" @@ -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" diff --git a/src/byteorder.rs b/src/byteorder.rs index 7b88049881..b6b4687c0f 100644 --- a/src/byteorder.rs +++ b/src/byteorder.rs @@ -63,6 +63,7 @@ use core::{ convert::{TryFrom, TryInto}, fmt::{Binary, Debug, LowerHex, Octal, UpperHex}, + hash::Hash, num::TryFromIntError, }; @@ -81,7 +82,7 @@ use super::*; /// /// [`U32`]: 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; @@ -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 { @@ -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 { @@ -1070,7 +1071,7 @@ mod tests { } trait ByteOrderType: - FromBytes + IntoBytes + Unaligned + Copy + Eq + Debug + From + FromBytes + IntoBytes + Unaligned + Copy + Eq + Debug + Hash + From { type Native: Native; type ByteArray: ByteArray; diff --git a/zerocopy-derive/Cargo.toml b/zerocopy-derive/Cargo.toml index 1f6c7af9cd..71d4b55dbb 100644 --- a/zerocopy-derive/Cargo.toml +++ b/zerocopy-derive/Cargo.toml @@ -9,7 +9,7 @@ [package] edition = "2021" name = "zerocopy-derive" -version = "0.8.4" +version = "0.8.5" authors = ["Joshua Liebow-Feeser "] description = "Custom derive for traits from the zerocopy crate" license = "BSD-2-Clause OR Apache-2.0 OR MIT"