Type Alias B256

Source
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>

Source

pub const ZERO: FixedBytes<N>

Array of Zero bytes.

Source

pub const fn new(bytes: [u8; N]) -> FixedBytes<N>

Wraps the given byte array in FixedBytes.

Source

pub const fn with_last_byte(x: u8) -> FixedBytes<N>

Creates a new FixedBytes with the last byte set to x.

Source

pub const fn repeat_byte(byte: u8) -> FixedBytes<N>

Creates a new FixedBytes where all bytes are set to byte.

Source

pub const fn len_bytes() -> usize

Returns the size of this byte array (N).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn as_slice(&self) -> &[u8]

Returns a slice containing the entire array. Equivalent to &s[..].

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

Source

pub fn covers(&self, other: &FixedBytes<N>) -> bool

Returns true if all bits set in self are also set in b.

Source

pub const fn const_covers(self, other: FixedBytes<N>) -> bool

Returns true if all bits set in self are also set in b.

Source

pub const fn const_eq(&self, other: &FixedBytes<N>) -> bool

Compile-time equality. NOT constant-time equality.

Source

pub fn is_zero(&self) -> bool

Returns true if no bits are set.

Source

pub const fn const_is_zero(&self) -> bool

Returns true if no bits are set.

Source

pub const fn bit_and(self, rhs: FixedBytes<N>) -> FixedBytes<N>

Computes the bitwise AND of two FixedBytes.

Source

pub const fn bit_or(self, rhs: FixedBytes<N>) -> FixedBytes<N>

Computes the bitwise OR of two FixedBytes.

Source

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> AsMut<[u8]> for FixedBytes<N>

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const N: usize> AsMut<[u8; N]> for FixedBytes<N>

Source§

fn as_mut(&mut self) -> &mut [u8; N]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const N: usize> AsRef<[u8]> for FixedBytes<N>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> AsRef<[u8; N]> for FixedBytes<N>

Source§

fn as_ref(&self) -> &[u8; N]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> BitAnd for FixedBytes<N>

Source§

type Output = FixedBytes<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitAnd>::Output

Performs the & operation. Read more
Source§

impl<const N: usize> BitAndAssign for FixedBytes<N>

Source§

fn bitand_assign(&mut self, rhs: FixedBytes<N>)

Performs the &= operation. Read more
Source§

impl<const N: usize> BitOr for FixedBytes<N>

Source§

type Output = FixedBytes<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitOr>::Output

Performs the | operation. Read more
Source§

impl<const N: usize> BitOrAssign for FixedBytes<N>

Source§

fn bitor_assign(&mut self, rhs: FixedBytes<N>)

Performs the |= operation. Read more
Source§

impl<const N: usize> BitXor for FixedBytes<N>

Source§

type Output = FixedBytes<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitXor>::Output

Performs the ^ operation. Read more
Source§

impl<const N: usize> BitXorAssign for FixedBytes<N>

Source§

fn bitxor_assign(&mut self, rhs: FixedBytes<N>)

Performs the ^= operation. Read more
Source§

impl<const N: usize> Borrow<[u8]> for FixedBytes<N>

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> Borrow<[u8; N]> for FixedBytes<N>

Source§

fn borrow(&self) -> &[u8; N]

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> BorrowMut<[u8]> for FixedBytes<N>

Source§

fn borrow_mut(&mut self) -> &mut [u8]

Mutably borrows from an owned value. Read more
Source§

impl<const N: usize> BorrowMut<[u8; N]> for FixedBytes<N>

Source§

fn borrow_mut(&mut self) -> &mut [u8; N]

Mutably borrows from an owned value. Read more
Source§

impl<const N: usize> Clone for FixedBytes<N>

Source§

fn clone(&self) -> FixedBytes<N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Decodable for FixedBytes<N>

Source§

fn decode(buf: &mut &[u8]) -> Result<FixedBytes<N>, Error>

Decodes the blob into the appropriate type. buf must be advanced past the decoded object.
Source§

impl<const N: usize> Default for FixedBytes<N>

Source§

fn default() -> FixedBytes<N>

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Deref for FixedBytes<N>

Source§

type Target = [u8; N]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<FixedBytes<N> as Deref>::Target

Dereferences the value.
Source§

impl<const N: usize> DerefMut for FixedBytes<N>

Source§

fn deref_mut(&mut self) -> &mut <FixedBytes<N> as Deref>::Target

Mutably dereferences the value.
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Display for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Encodable for FixedBytes<N>

Source§

fn length(&self) -> usize

Returns the length of the encoding of this type in bytes. Read more
Source§

fn encode(&self, out: &mut dyn BufMut)

Encodes the type into the out buffer.
Source§

impl<const N: usize> From<&[u8; N]> for FixedBytes<N>

Source§

fn from(bytes: &[u8; N]) -> FixedBytes<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<&mut [u8; N]> for FixedBytes<N>

Source§

fn from(bytes: &mut [u8; N]) -> FixedBytes<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<[u8; N]> for FixedBytes<N>

Source§

fn from(value: [u8; N]) -> FixedBytes<N>

Converts to this type from the input type.
Source§

impl From<Signed<256, 4>> for FixedBytes<32>

Source§

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>

Source§

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>

Source§

type Error = FromHexError

The associated error which can be returned from parsing.
Source§

fn from_hex<T>( hex: T, ) -> Result<FixedBytes<N>, <FixedBytes<N> as FromHex>::Error>
where T: AsRef<[u8]>,

Creates an instance of type Self from the given hex string, or fails with a custom error type. Read more
Source§

impl<const N: usize> FromStr for FixedBytes<N>

Source§

type Err = FromHexError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<FixedBytes<N>, <FixedBytes<N> as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const N: usize> Hash for FixedBytes<N>

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<__IdxT, const N: usize> Index<__IdxT> for FixedBytes<N>
where [u8; N]: Index<__IdxT>,

Source§

type Output = <[u8; N] as Index<__IdxT>>::Output

The returned type after indexing.
Source§

fn index(&self, idx: __IdxT) -> &<FixedBytes<N> as Index<__IdxT>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<__IdxT, const N: usize> IndexMut<__IdxT> for FixedBytes<N>
where [u8; N]: IndexMut<__IdxT>,

Source§

fn index_mut( &mut self, idx: __IdxT, ) -> &mut <FixedBytes<N> as Index<__IdxT>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<const N: usize> IntoIterator for FixedBytes<N>
where [u8; N]: IntoIterator,

Source§

type Item = <[u8; N] as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <[u8; N] as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <FixedBytes<N> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const N: usize> LowerHex for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> MaxEncodedLenAssoc for FixedBytes<N>

Source§

const LEN: usize

The maximum length.
Source§

impl<const N: usize> Not for FixedBytes<N>

Source§

type Output = FixedBytes<N>

The resulting type after applying the ! operator.
Source§

fn not(self) -> <FixedBytes<N> as Not>::Output

Performs the unary ! operation. Read more
Source§

impl<const N: usize> Ord for FixedBytes<N>

Source§

fn cmp(&self, other: &FixedBytes<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: usize> PartialEq<&[u8]> for FixedBytes<N>

Source§

fn eq(&self, other: &&[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<&[u8; N]> for FixedBytes<N>

Source§

fn eq(&self, other: &&[u8; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<[u8]> for FixedBytes<N>

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<[u8; N]> for FixedBytes<N>

Source§

fn eq(&self, other: &[u8; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq for FixedBytes<N>

Source§

fn eq(&self, other: &FixedBytes<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialOrd<&[u8]> for FixedBytes<N>

Source§

fn partial_cmp(&self, other: &&[u8]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> PartialOrd<[u8]> for FixedBytes<N>

Source§

fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> PartialOrd for FixedBytes<N>

Source§

fn partial_cmp(&self, other: &FixedBytes<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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,

Serialize this value into the given Serde serializer. Read more
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.

Source§

type Error = TryFromSliceError

The type returned in the event of a conversion error.
Source§

fn try_from( slice: &[u8], ) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&[u8]>>::Error>

Performs the conversion.
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.

Source§

type Error = TryFromSliceError

The type returned in the event of a conversion error.
Source§

fn try_from( slice: &mut [u8], ) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&mut [u8]>>::Error>

Performs the conversion.
Source§

impl<const N: usize> UpperHex for FixedBytes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Copy for FixedBytes<N>

Source§

impl<const N: usize> Eq for FixedBytes<N>

Source§

impl MaxEncodedLen<alloy_primitives::::bits::rlp::{impl#10}::{constant#0}> for FixedBytes<32>

Source§

impl<const N: usize> StructuralPartialEq for FixedBytes<N>