pub trait RawDataSerializable: Sized {
const NUM_BYTES: usize;
// Required method
fn into_bytes(self) -> impl IntoIterator<Item = u8>;
// Provided methods
fn into_byte_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u8> { ... }
fn into_u32_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u32> { ... }
fn into_u64_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u64> { ... }
fn into_parallel_byte_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u8; N]> { ... }
fn into_parallel_u32_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u32; N]> { ... }
fn into_parallel_u64_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u64; N]> { ... }
}Expand description
A collection of methods designed to help hash field elements.
Most fields will want to reimplement many/all of these methods as the default implementations are slow and involve converting to/from byte representations.
Required Associated Constants§
Required Methods§
Sourcefn into_bytes(self) -> impl IntoIterator<Item = u8>
fn into_bytes(self) -> impl IntoIterator<Item = u8>
Convert a field element into a collection of bytes.
Provided Methods§
Sourcefn into_byte_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u8>
fn into_byte_stream( input: impl IntoIterator<Item = Self>, ) -> impl IntoIterator<Item = u8>
Convert an iterator of field elements into an iterator of bytes.
Sourcefn into_u32_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u32>
fn into_u32_stream( input: impl IntoIterator<Item = Self>, ) -> impl IntoIterator<Item = u32>
Convert an iterator of field elements into an iterator of u32s.
If NUM_BYTES does not divide 4, multiple Fs may be packed together to make a single u32. Furthermore,
if NUM_BYTES * input.len() does not divide 4, the final u32 will involve padding bytes which are set to 0.
Sourcefn into_u64_stream(
input: impl IntoIterator<Item = Self>,
) -> impl IntoIterator<Item = u64>
fn into_u64_stream( input: impl IntoIterator<Item = Self>, ) -> impl IntoIterator<Item = u64>
Convert an iterator of field elements into an iterator of u64s.
If NUM_BYTES does not divide 8, multiple Fs may be packed together to make a single u64. Furthermore,
if NUM_BYTES * input.len() does not divide 8, the final u64 will involve padding bytes which are set to 0.
Sourcefn into_parallel_byte_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u8; N]>
fn into_parallel_byte_streams<const N: usize>( input: impl IntoIterator<Item = [Self; N]>, ) -> impl IntoIterator<Item = [u8; N]>
Convert an iterator of field element arrays into an iterator of byte arrays.
Converts an element [F; N] into the byte array [[u8; N]; NUM_BYTES]. This is
intended for use with vectorized hash functions which use vector operations
to compute several hashes in parallel.
Sourcefn into_parallel_u32_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u32; N]>
fn into_parallel_u32_streams<const N: usize>( input: impl IntoIterator<Item = [Self; N]>, ) -> impl IntoIterator<Item = [u32; N]>
Convert an iterator of field element arrays into an iterator of u32 arrays.
Converts an element [F; N] into the u32 array [[u32; N]; NUM_BYTES/4]. This is
intended for use with vectorized hash functions which use vector operations
to compute several hashes in parallel.
This function is guaranteed to be equivalent to starting with Iterator<[F; N]> performing a transpose
operation to get [Iterator<F>; N], calling into_u32_stream on each element to get [Iterator<u32>; N] and then
performing another transpose operation to get Iterator<[u32; N]>.
If NUM_BYTES does not divide 4, multiple [F; N]s may be packed together to make a single [u32; N]. Furthermore,
if NUM_BYTES * input.len() does not divide 4, the final [u32; N] will involve padding bytes which are set to 0.
Sourcefn into_parallel_u64_streams<const N: usize>(
input: impl IntoIterator<Item = [Self; N]>,
) -> impl IntoIterator<Item = [u64; N]>
fn into_parallel_u64_streams<const N: usize>( input: impl IntoIterator<Item = [Self; N]>, ) -> impl IntoIterator<Item = [u64; N]>
Convert an iterator of field element arrays into an iterator of u64 arrays.
Converts an element [F; N] into the u64 array [[u64; N]; NUM_BYTES/8]. This is
intended for use with vectorized hash functions which use vector operations
to compute several hashes in parallel.
This function is guaranteed to be equivalent to starting with Iterator<[F; N]> performing a transpose
operation to get [Iterator<F>; N], calling into_u64_stream on each element to get [Iterator<u64>; N] and then
performing another transpose operation to get Iterator<[u64; N]>.
If NUM_BYTES does not divide 8, multiple [F; N]s may be packed together to make a single [u64; N]. Furthermore,
if NUM_BYTES * input.len() does not divide 8, the final [u64; N] will involve padding bytes which are set to 0.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.