From 362533deff4d37b9ff3a1dc78163fe70fbed9aa4 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 15 Dec 2025 17:15:28 -0800 Subject: [PATCH] Add supertraits to `PrimitiveNumber::Bytes` Maybe someday const-generics will let us use `[u8; size_of::()]` instead of this associated type, but for now we can make it more useful by adding a bunch of supertraits that are implemented by `[u8; N]`. --- src/number.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/number.rs b/src/number.rs index bbb88a5..8c43c33 100644 --- a/src/number.rs +++ b/src/number.rs @@ -102,7 +102,23 @@ pub trait PrimitiveNumber: { /// An array of bytes used by methods like [`from_be_bytes`][Self::from_be_bytes] and /// [`to_be_bytes`][Self::to_be_bytes]. It is effectively `[u8; size_of::()]`. - type Bytes: core::borrow::Borrow<[u8]> + core::borrow::BorrowMut<[u8]>; + type Bytes: 'static + + core::borrow::Borrow<[u8]> + + core::borrow::BorrowMut<[u8]> + + core::cmp::Eq + + core::cmp::Ord + + core::cmp::PartialEq<[u8]> + + core::convert::AsRef<[u8]> + + core::convert::AsMut<[u8]> + + core::default::Default + + core::fmt::Debug + + core::hash::Hash + + core::marker::Copy + + core::marker::Send + + core::marker::Sync + + core::marker::Unpin + + core::panic::RefUnwindSafe + + core::panic::UnwindSafe; /// Creates a number from its representation as a byte array in big endian. fn from_be_bytes(bytes: Self::Bytes) -> Self;