pub trait TowerLevel<T>{
type Data: AsMut<[T]> + AsRef<[T]> + Sized + Index<usize, Output = T> + IndexMut<usize, Output = T>;
type Base: TowerLevel<T>;
const WIDTH: usize;
// Required methods
fn split(
data: &Self::Data,
) -> (&<Self::Base as TowerLevel<T>>::Data, &<Self::Base as TowerLevel<T>>::Data);
fn split_mut(
data: &mut Self::Data,
) -> (&mut <Self::Base as TowerLevel<T>>::Data, &mut <Self::Base as TowerLevel<T>>::Data);
fn join(
first: &<Self::Base as TowerLevel<T>>::Data,
second: &<Self::Base as TowerLevel<T>>::Data,
) -> Self::Data;
fn from_fn(f: impl Fn(usize) -> T) -> Self::Data;
// Provided method
fn default() -> Self::Data { ... }
}
Expand description
Public API for recursive algorithms over data represented as an array of its limbs E.g. an F_{2^128} element expressed as 8 chunks of 2 bytes or a 256-bit integer represented as 32 individual bytes
Join and split can be used to combine and split underlying data into upper and lower halves
This is mostly useful for recursively implementing arithmetic operations
These separate implementations are necessary to overcome the limitations of const generics in Rust. These implementations eliminate costly bounds checking that would otherwise be imposed by the compiler and allow easy inlining of recursive functions.
Required Associated Constants§
Required Associated Types§
type Data: AsMut<[T]> + AsRef<[T]> + Sized + Index<usize, Output = T> + IndexMut<usize, Output = T>
type Base: TowerLevel<T>
Required Methods§
fn split( data: &Self::Data, ) -> (&<Self::Base as TowerLevel<T>>::Data, &<Self::Base as TowerLevel<T>>::Data)
fn split_mut( data: &mut Self::Data, ) -> (&mut <Self::Base as TowerLevel<T>>::Data, &mut <Self::Base as TowerLevel<T>>::Data)
fn join( first: &<Self::Base as TowerLevel<T>>::Data, second: &<Self::Base as TowerLevel<T>>::Data, ) -> Self::Data
fn from_fn(f: impl Fn(usize) -> T) -> Self::Data
Provided Methods§
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.