pub type B256 = FixedBytes<32>;
Expand description
32-byte fixed byte-array type.
Aliased Type§
struct B256(pub [u8; 32]);
Fields§
§0: [u8; 32]
Implementations
Source§impl<const N: usize> FixedBytes<N>
impl<const N: usize> FixedBytes<N>
Sourcepub const ZERO: FixedBytes<N>
pub const ZERO: FixedBytes<N>
Array of Zero bytes.
Sourcepub const fn new(bytes: [u8; N]) -> FixedBytes<N>
pub const fn new(bytes: [u8; N]) -> FixedBytes<N>
Wraps the given byte array in FixedBytes
.
Sourcepub const fn with_last_byte(x: u8) -> FixedBytes<N>
pub const fn with_last_byte(x: u8) -> FixedBytes<N>
Creates a new FixedBytes
with the last byte set to x
.
Sourcepub const fn repeat_byte(byte: u8) -> FixedBytes<N>
pub const fn repeat_byte(byte: u8) -> FixedBytes<N>
Creates a new FixedBytes
where all bytes are set to byte
.
Sourcepub const fn concat_const<const M: usize, const Z: usize>(
self,
other: FixedBytes<M>,
) -> FixedBytes<Z>
pub const fn concat_const<const M: usize, const Z: usize>( self, other: FixedBytes<M>, ) -> FixedBytes<Z>
Concatenate two FixedBytes
.
Due to constraints in the language, the user must specify the value of
the output size Z
.
§Panics
Panics if Z
is not equal to N + M
.
Sourcepub fn from_slice(src: &[u8]) -> FixedBytes<N>
pub fn from_slice(src: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
.
For a fallible version, use the TryFrom<&[u8]>
implementation.
§Note
The given bytes are interpreted in big endian order.
§Panics
If the length of src
and the number of bytes in Self
do not match.
Sourcepub fn left_padding_from(value: &[u8]) -> FixedBytes<N>
pub fn left_padding_from(value: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
, left-padding it
with zeroes if necessary.
§Note
The given bytes are interpreted in big endian order.
§Panics
Panics if src.len() > N
.
Sourcepub fn right_padding_from(value: &[u8]) -> FixedBytes<N>
pub fn right_padding_from(value: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
, right-padding it
with zeroes if necessary.
§Note
The given bytes are interpreted in big endian order.
§Panics
Panics if src.len() > N
.
Sourcepub const fn as_slice(&self) -> &[u8] ⓘ
pub const fn as_slice(&self) -> &[u8] ⓘ
Returns a slice containing the entire array. Equivalent to &s[..]
.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
Sourcepub fn covers(&self, other: &FixedBytes<N>) -> bool
pub fn covers(&self, other: &FixedBytes<N>) -> bool
Returns true
if all bits set in self
are also set in b
.
Sourcepub const fn const_covers(self, other: FixedBytes<N>) -> bool
pub const fn const_covers(self, other: FixedBytes<N>) -> bool
Returns true
if all bits set in self
are also set in b
.
Sourcepub const fn const_eq(&self, other: &FixedBytes<N>) -> bool
pub const fn const_eq(&self, other: &FixedBytes<N>) -> bool
Compile-time equality. NOT constant-time equality.
Sourcepub const fn const_is_zero(&self) -> bool
pub const fn const_is_zero(&self) -> bool
Returns true
if no bits are set.
Sourcepub const fn bit_and(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_and(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise AND of two FixedBytes
.
Sourcepub const fn bit_or(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_or(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise OR of two FixedBytes
.
Sourcepub const fn bit_xor(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_xor(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise XOR of two FixedBytes
.
Trait Implementations
Source§impl<const N: usize> BitAnd for FixedBytes<N>
impl<const N: usize> BitAnd for FixedBytes<N>
Source§type Output = FixedBytes<N>
type Output = FixedBytes<N>
&
operator.Source§fn bitand(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitAnd>::Output
fn bitand(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitAnd>::Output
&
operation. Read moreSource§impl<const N: usize> BitAndAssign for FixedBytes<N>
impl<const N: usize> BitAndAssign for FixedBytes<N>
Source§fn bitand_assign(&mut self, rhs: FixedBytes<N>)
fn bitand_assign(&mut self, rhs: FixedBytes<N>)
&=
operation. Read moreSource§impl<const N: usize> BitOr for FixedBytes<N>
impl<const N: usize> BitOr for FixedBytes<N>
Source§type Output = FixedBytes<N>
type Output = FixedBytes<N>
|
operator.Source§fn bitor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitOr>::Output
fn bitor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitOr>::Output
|
operation. Read moreSource§impl<const N: usize> BitOrAssign for FixedBytes<N>
impl<const N: usize> BitOrAssign for FixedBytes<N>
Source§fn bitor_assign(&mut self, rhs: FixedBytes<N>)
fn bitor_assign(&mut self, rhs: FixedBytes<N>)
|=
operation. Read moreSource§impl<const N: usize> BitXor for FixedBytes<N>
impl<const N: usize> BitXor for FixedBytes<N>
Source§type Output = FixedBytes<N>
type Output = FixedBytes<N>
^
operator.Source§fn bitxor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitXor>::Output
fn bitxor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitXor>::Output
^
operation. Read moreSource§impl<const N: usize> BitXorAssign for FixedBytes<N>
impl<const N: usize> BitXorAssign for FixedBytes<N>
Source§fn bitxor_assign(&mut self, rhs: FixedBytes<N>)
fn bitxor_assign(&mut self, rhs: FixedBytes<N>)
^=
operation. Read moreSource§impl<const N: usize> Clone for FixedBytes<N>
impl<const N: usize> Clone for FixedBytes<N>
Source§fn clone(&self) -> FixedBytes<N>
fn clone(&self) -> FixedBytes<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<const N: usize> Debug for FixedBytes<N>
impl<const N: usize> Debug for FixedBytes<N>
Source§impl<const N: usize> Decodable for FixedBytes<N>
impl<const N: usize> Decodable for FixedBytes<N>
Source§impl<const N: usize> Default for FixedBytes<N>
impl<const N: usize> Default for FixedBytes<N>
Source§fn default() -> FixedBytes<N>
fn default() -> FixedBytes<N>
Source§impl<const N: usize> Deref for FixedBytes<N>
impl<const N: usize> Deref for FixedBytes<N>
Source§impl<const N: usize> DerefMut for FixedBytes<N>
impl<const N: usize> DerefMut for FixedBytes<N>
Source§impl<'de, const N: usize> Deserialize<'de> for FixedBytes<N>
impl<'de, const N: usize> Deserialize<'de> for FixedBytes<N>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<FixedBytes<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<FixedBytes<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize> Display for FixedBytes<N>
impl<const N: usize> Display for FixedBytes<N>
Source§impl<const N: usize> Encodable for FixedBytes<N>
impl<const N: usize> Encodable for FixedBytes<N>
Source§impl From<Signed<256, 4>> for FixedBytes<32>
impl From<Signed<256, 4>> for FixedBytes<32>
Source§fn from(value: Signed<256, 4>) -> FixedBytes<32>
fn from(value: Signed<256, 4>) -> FixedBytes<32>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
Source§impl From<Uint<256, 4>> for FixedBytes<32>
impl From<Uint<256, 4>> for FixedBytes<32>
Source§fn from(value: Uint<256, 4>) -> FixedBytes<32>
fn from(value: Uint<256, 4>) -> FixedBytes<32>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
Source§impl<const N: usize> FromHex for FixedBytes<N>
impl<const N: usize> FromHex for FixedBytes<N>
Source§type Error = FromHexError
type Error = FromHexError
Source§impl<const N: usize> FromStr for FixedBytes<N>
impl<const N: usize> FromStr for FixedBytes<N>
Source§type Err = FromHexError
type Err = FromHexError
Source§fn from_str(s: &str) -> Result<FixedBytes<N>, <FixedBytes<N> as FromStr>::Err>
fn from_str(s: &str) -> Result<FixedBytes<N>, <FixedBytes<N> as FromStr>::Err>
s
to return a value of this type. Read moreSource§impl<const N: usize> Hash for FixedBytes<N>
impl<const N: usize> Hash for FixedBytes<N>
Source§impl<__IdxT, const N: usize> Index<__IdxT> for FixedBytes<N>
impl<__IdxT, const N: usize> Index<__IdxT> for FixedBytes<N>
Source§impl<__IdxT, const N: usize> IndexMut<__IdxT> for FixedBytes<N>
impl<__IdxT, const N: usize> IndexMut<__IdxT> for FixedBytes<N>
Source§impl<const N: usize> IntoIterator for FixedBytes<N>
impl<const N: usize> IntoIterator for FixedBytes<N>
Source§type IntoIter = <[u8; N] as IntoIterator>::IntoIter
type IntoIter = <[u8; N] as IntoIterator>::IntoIter
Source§fn into_iter(self) -> <FixedBytes<N> as IntoIterator>::IntoIter
fn into_iter(self) -> <FixedBytes<N> as IntoIterator>::IntoIter
Source§impl<const N: usize> LowerHex for FixedBytes<N>
impl<const N: usize> LowerHex for FixedBytes<N>
Source§impl<const N: usize> MaxEncodedLenAssoc for FixedBytes<N>
impl<const N: usize> MaxEncodedLenAssoc for FixedBytes<N>
Source§impl<const N: usize> Not for FixedBytes<N>
impl<const N: usize> Not for FixedBytes<N>
Source§impl<const N: usize> Ord for FixedBytes<N>
impl<const N: usize> Ord for FixedBytes<N>
Source§fn cmp(&self, other: &FixedBytes<N>) -> Ordering
fn cmp(&self, other: &FixedBytes<N>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const N: usize> PartialEq for FixedBytes<N>
impl<const N: usize> PartialEq for FixedBytes<N>
Source§impl<const N: usize> PartialOrd<&[u8]> for FixedBytes<N>
impl<const N: usize> PartialOrd<&[u8]> for FixedBytes<N>
Source§impl<const N: usize> PartialOrd<[u8]> for FixedBytes<N>
impl<const N: usize> PartialOrd<[u8]> for FixedBytes<N>
Source§impl<const N: usize> PartialOrd for FixedBytes<N>
impl<const N: usize> PartialOrd for FixedBytes<N>
Source§impl<const N: usize> Serialize for FixedBytes<N>
impl<const N: usize> Serialize for FixedBytes<N>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<const N: usize> TryFrom<&[u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a slice &[u8]
. Succeeds
if slice.len() == N
.
impl<const N: usize> TryFrom<&[u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a slice &[u8]
. Succeeds
if slice.len() == N
.
Source§type Error = TryFromSliceError
type Error = TryFromSliceError
Source§fn try_from(
slice: &[u8],
) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&[u8]>>::Error>
fn try_from( slice: &[u8], ) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&[u8]>>::Error>
Source§impl<const N: usize> TryFrom<&mut [u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a mutable slice &mut [u8]
. Succeeds if slice.len() == N
.
impl<const N: usize> TryFrom<&mut [u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a mutable slice &mut [u8]
. Succeeds if slice.len() == N
.