### Reed-Solomon Encode and Decode Example (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/index Demonstrates the basic usage of the reed-solomon-simd crate for encoding data into recovery shards and decoding lost original shards. It highlights the process of dividing data, generating recovery shards, and restoring lost shards using a combination of available original and recovery shards. The example assumes shard size is even and shows how to handle missing shards. ```rust let original = [ b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ", b"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e", b"nim ad minim veniam, quis nostrud exercitation ullamco laboris n", ]; let recovery = reed_solomon_simd::encode( 3, // total number of original shards 5, // total number of recovery shards original, // all original shards )?; let restored = reed_solomon_simd::decode( 3, // total number of original shards 5, // total number of recovery shards [ (1, &original[1]), ], [ (1, &recovery[1]), (4, &recovery[4]), ], )?; assert_eq!(restored[&0], original[0]); assert_eq!(restored[&2], original[2]); ``` -------------------------------- ### Manipulate ShardsRefMut in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Includes methods for checking if `ShardsRefMut` is empty, getting the total number of shards, and splitting the `ShardsRefMut` into two separate instances. The `zero` method efficiently fills a specified range of shards with zero bytes. ```rust pub fn is_empty(&self) -> bool pub fn len(&self) -> usize pub fn split_at_mut( &mut self, mid: usize, ) -> (ShardsRefMut<'_>, ShardsRefMut<'_>) pub fn zero>(&mut self, range: R) ``` -------------------------------- ### Get TypeId of Self Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum The `type_id` function returns the `TypeId` of the current type. This is useful for runtime type identification and comparisons. ```rust fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Index Implementation for ShardsRefMut Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Details on how ShardsRefMut can be indexed to access individual shards. ```APIDOC ## Trait Implementations ### impl Index for ShardsRefMut<'_> #### type Output = [[u8; 64]] **Description**: The type returned after indexing. #### fn index(&self, index: usize) -> &Self::Output **Description**: Performs the indexing (`container[index]`) operation. **Method**: `&self` **Parameters**: - `index` (usize): The index of the shard to access. ### impl IndexMut for ShardsRefMut<'_> #### fn index_mut(&mut self, index: usize) -> &mut Self::Output **Description**: Performs the mutable indexing (`container[index]`) operation. **Method**: `&mut self` **Parameters**: - `index` (usize): The index of the shard to access mutably. ``` -------------------------------- ### ExactSizeIterator for RestoredOriginal Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct Provides exact size information for the `RestoredOriginal` iterator. ```APIDOC ## Trait Implementation: ExactSizeIterator for RestoredOriginal<'_> ### Methods #### `len()` * **Description**: Returns the exact remaining length of the iterator. * **Signature**: `fn len(&self) -> usize` #### `is_empty()` * **Description**: Returns `true` if the iterator is empty. (Nightly-only experimental API) * **Signature**: `fn is_empty(&self) -> bool` ``` -------------------------------- ### Basic Reed-Solomon Encoding and Decoding in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/index Demonstrates the basic usage of ReedSolomonEncoder and ReedSolomonDecoder for data integrity. It shows how to initialize the encoder, add original shards, generate recovery shards, and then use the decoder with a mix of original and recovery shards to restore missing data. This process is crucial for fault tolerance in data storage and transmission. ```Rust use reed_solomon_simd::{ReedSolomonDecoder, ReedSolomonEncoder}; use std::collections::HashMap; let original = [ b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ", b"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e", b"nim ad minim veniam, quis nostrud exercitation ullamco laboris n", ]; let mut encoder = ReedSolomonEncoder::new( 3, // total number of original shards 5, // total number of recovery shards 64, // shard size in bytes )?; for shard in original { encoder.add_original_shard(shard)?; } let result = encoder.encode()?; let recovery: Vec<_> = result.recovery_iter().collect(); let mut decoder = ReedSolomonDecoder::new( 3, // total number of original shards 5, // total number of recovery shards 64, // shard size in bytes )?; decoder.add_original_shard(1, original[1])?; decoder.add_recovery_shard(1, recovery[1])?; decoder.add_recovery_shard(4, recovery[4])?; let result = decoder.decode()?; let restored: HashMap<_, _> = result.restored_original_iter().collect(); assert_eq!(restored[&0], original[0]); assert_eq!(restored[&2], original[2]); ``` -------------------------------- ### ShardsRefMut Methods Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Documentation for the methods available on the ShardsRefMut struct, which allows for mutable operations on shard arrays. ```APIDOC ## Struct ShardsRefMut Mutable reference to a shard array. ### Methods #### `dist2_mut(&mut self, pos: usize, dist: usize) -> (&mut [[u8; 64]], &mut [[u8; 64]])` **Description**: Returns mutable references to shards at `pos` and `pos + dist`. **Method**: `&mut self` **Parameters**: - `pos` (usize): The starting position of the first shard. - `dist` (usize): The distance between the two shards. **Panics**: If `dist` is `0`. #### `dist4_mut(&mut self, pos: usize, dist: usize) -> (&mut [[u8; 64]], &mut [[u8; 64]], &mut [[u8; 64]], &mut [[u8; 64]])` **Description**: Returns mutable references to shards at `pos`, `pos + dist`, `pos + dist * 2`, and `pos + dist * 3`. **Method**: `&mut self` **Parameters**: - `pos` (usize): The starting position of the first shard. - `dist` (usize): The distance between consecutive shards. **Panics**: If `dist` is `0`. #### `is_empty(&self) -> bool` **Description**: Returns `true` if this contains no shards. **Method**: `&self` #### `len(&self) -> usize` **Description**: Returns the number of shards. **Method**: `&self` #### `new(shard_count: usize, shard_len_64: usize, data: &'a mut [[u8; 64]]) -> Self` **Description**: Creates a new `ShardsRefMut` that references the given `data`. **Method**: `new` **Parameters**: - `shard_count` (usize): The total number of shards. - `shard_len_64` (usize): The length of each shard in 64-byte units. - `data` (&'a mut [[u8; 64]]): A mutable slice of 64-byte arrays representing the shard data. **Panics**: If `data.len() < shard_count * shard_len_64`. #### `split_at_mut(&mut self, mid: usize) -> (ShardsRefMut<'_>, ShardsRefMut<'_>)` **Description**: Splits this `ShardsRefMut` into two so that the first includes shards `0..mid` and the second includes shards `mid..`. **Method**: `&mut self` **Parameters**: - `mid` (usize): The index at which to split the shards. #### `zero>(&mut self, range: R)` **Description**: Fills the given shard-range with `0u8`s. **Method**: `&mut self` **Parameters**: - `range` (R: RangeBounds): The range of shards to fill with zeros. ``` -------------------------------- ### Implement Blanket Implementations for Generic Types in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/struct Demonstrates blanket implementations for generic types in Rust, showcasing conversions and trait bounds. This includes implementations for Any, Borrow, BorrowMut, From, Into, TryFrom, and TryInto, allowing for flexible type manipulation and interoperability. ```rust impl Any for T where T: 'static + ?Sized, impl Borrow for T where T: ?Sized, impl BorrowMut for T where T: ?Sized, impl From for T, impl Into for T where U: From, impl TryFrom for T where U: Into, impl TryInto for T where U: TryFrom ``` -------------------------------- ### Iterator for RestoredOriginal Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct Defines the iteration behavior for the `RestoredOriginal` struct. ```APIDOC ## Trait Implementation: Iterator for RestoredOriginal<'_> ### Associated Types #### `Item` * **Description**: The type of the elements being iterated over. * **Type**: `(usize, &'a [u8])` - A tuple containing the shard index and a slice of the shard's data. ``` ```APIDOC ### Methods #### `next()` * **Description**: Advances the iterator and returns the next value. * **Signature**: `fn next(&mut self) -> Option<(usize, &'a [u8])>` * **Returns**: `Some((index, shard_data))` if there is a next element, `None` otherwise. ``` ```APIDOC #### `size_hint()` * **Description**: Returns the bounds on the remaining length of the iterator. * **Signature**: `fn size_hint(&self) -> (usize, Option)` * **Returns**: A tuple `(lower_bound, upper_bound)`. ``` ```APIDOC #### `next_chunk::()` * **Description**: Advances the iterator and returns an array containing the next `N` values. (Nightly-only experimental API) * **Signature**: `fn next_chunk(&mut self) -> Result<[Self::Item; N], IntoIter>` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `count()` * **Description**: Consumes the iterator, counting the number of iterations and returning it. * **Signature**: `fn count(self) -> usize` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `last()` * **Description**: Consumes the iterator, returning the last element. * **Signature**: `fn last(self) -> Option` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `advance_by()` * **Description**: Advances the iterator by `n` elements. (Nightly-only experimental API) * **Signature**: `fn advance_by(&mut self, n: usize) -> Result<(), NonZero>` * **Returns**: `Ok(())` if successful, `Err(remaining_n)` if not advanced by `n` elements. ``` ```APIDOC #### `nth()` * **Description**: Returns the `n`th element of the iterator. * **Signature**: `fn nth(&mut self, n: usize) -> Option` ``` ```APIDOC #### `step_by()` * **Description**: Creates an iterator starting at the same point, but stepping by the given amount at each iteration. * **Signature**: `fn step_by(self, step: usize) -> StepBy` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `chain()` * **Description**: Takes two iterators and creates a new iterator over both in sequence. * **Signature**: `fn chain(self, other: U) -> Chain::IntoIter>` * **Note**: Requires `Self: Sized` and `U: IntoIterator`. ``` ```APIDOC #### `zip()` * **Description**: ‘Zips up’ two iterators into a single iterator of pairs. * **Signature**: `fn zip(self, other: U) -> Zip::IntoIter>` * **Note**: Requires `Self: Sized` and `U: IntoIterator`. ``` ```APIDOC #### `intersperse()` * **Description**: Creates a new iterator which places a copy of `separator` between adjacent items of the original iterator. (Nightly-only experimental API) * **Signature**: `fn intersperse(self, separator: Self::Item) -> Intersperse` * **Note**: Requires `Self: Sized` and `Self::Item: Clone`. ``` ```APIDOC #### `intersperse_with()` * **Description**: Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. (Nightly-only experimental API) * **Signature**: `fn intersperse_with(self, separator: G) -> IntersperseWith` * **Note**: Requires `Self: Sized` and `G: FnMut() -> Self::Item`. ``` ```APIDOC #### `map()` * **Description**: Takes a closure and creates an iterator which calls that closure on each element. * **Signature**: `fn map(self, f: F) -> Map` * **Note**: Requires `Self: Sized` and `F: FnMut(Self::Item) -> B`. ``` ```APIDOC #### `for_each()` * **Description**: Calls a closure on each element of an iterator. * **Signature**: `fn for_each(self, f: F)` * **Note**: Requires `Self: Sized` and `F: FnMut(Self::Item)`. ``` ```APIDOC #### `filter()` * **Description**: Creates an iterator which uses a closure to determine if an element should be yielded. * **Signature**: `fn filter

(self, predicate: P) -> Filter` * **Note**: Requires `Self: Sized` and `P: FnMut(&Self::Item) -> bool`. ``` ```APIDOC #### `filter_map()` * **Description**: Creates an iterator that both filters and maps. * **Signature**: `fn filter_map(self, f: F) -> FilterMap` * **Note**: Requires `Self: Sized` and `F: FnMut(Self::Item) -> Option`. ``` ```APIDOC #### `enumerate()` * **Description**: Creates an iterator which gives the current iteration count as well as the next value. * **Signature**: `fn enumerate(self) -> Enumerate` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `peekable()` * **Description**: Creates an iterator which can use the `peek` and `peek_mut` methods to look at the next element of the iterator without consuming it. * **Signature**: `fn peekable(self) -> Peekable` * **Note**: Requires `Self: Sized`. ``` ```APIDOC #### `skip_while()` * **Description**: Creates an iterator that `skip`s elements based on a predicate. * **Signature**: `fn skip_while

(self, predicate: P) -> SkipWhile` * **Note**: Requires `Self: Sized` and `P: FnMut(&Self::Item) -> bool`. ``` ```APIDOC #### `take_while()` * **Description**: Creates an iterator that yields elements based on a predicate. * **Signature**: `fn take_while

(self, predicate: P) -> TakeWhile` * **Note**: Requires `Self: Sized` and `P: FnMut(&Self::Item) -> bool`. ``` -------------------------------- ### Blanket Implementations for Generic Types in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Demonstrates blanket implementations for generic types `T` and `U`, showcasing common trait implementations like `Any`, `Borrow`, `BorrowMut`, `From`, `Into`, `TryFrom`, and `TryInto`. These are standard Rust features that provide fundamental functionalities for generic types, including identity conversions and type conversions with error handling. ```rust impl Any for T where T: 'static + ?Sized impl Borrow for T where T: ?Sized impl BorrowMut for T where T: ?Sized impl From for T impl Into for T where U: From impl TryFrom for T where U: Into impl TryInto for T where U: TryFrom ``` -------------------------------- ### Low Rate Encoding Algorithm Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/algorithm/index Describes the algorithm for low rate encoding. Encoding uses chunks based on the next power of two of the original count. Original shards form a single chunk, possibly padded. Recovery shards are generated individually by applying FFT to the IFFT of the original chunk, each combined with a specific skew. ```text recovery_chunk_0 = FFT( IFFT(original_chunk), skew_0 ) recovery_chunk_1 = FFT( IFFT(original_chunk), skew_1 ) ... ``` -------------------------------- ### Reed-Solomon SIMD Engine FFT Method (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/trait Implements the 'fft' method within the 'Engine' trait for in-place decimation-in-time Fast Fourier Transform. It operates on a specified chunk of data and requires the size to be a power of two. ```rust fn fft( &self, data: &mut ShardsRefMut<'_>, pos: usize, size: usize, truncated_size: usize, skew_delta: usize, ) ``` -------------------------------- ### Implement Indexing for ShardsRefMut in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Implements the `Index` and `IndexMut` traits for `ShardsRefMut`, allowing direct access to individual shards using square bracket notation. This enables both immutable and mutable access to shards based on their index within the `ShardsRefMut` collection. ```rust impl Index for ShardsRefMut<'_> impl IndexMut for ShardsRefMut<'_> ``` -------------------------------- ### Create ShardsRefMut Instance in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Constructs a new `ShardsRefMut` instance. This function takes the number of shards, the length of each shard in 64-byte units, and a mutable reference to the data array. It panics if the provided data array is not large enough to accommodate the specified shard count and length. ```rust pub fn new( shard_count: usize, shard_len_64: usize, data: &'a mut [[u8; 64]], ) -> Self ``` -------------------------------- ### Shard Structure for SIMD Optimization (Conceptual) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/algorithm/index Illustrates the byte-level interpretation of shards for SIMD processing. Unlike naive approaches, this structure aligns data into 64-byte blocks, with the first 32 bytes representing low parts and the next 32 bytes representing high parts of 32 GfElement instances. This arrangement is crucial for efficient SIMD operations. ```text [ low_0, low_1, ..., low_31, high_0, high_1, ..., high_31 ] // -------- first 64-byte block --------- | --------- second 64-byte block ---------- | ... [ low_0, ..., low_31, high_0, ..., high_31, low_32, ..., low_63, high_32, ..., high_63, ... ] ``` -------------------------------- ### Reed-Solomon SIMD Engine IFFT Method (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/trait Implements the 'ifft' method within the 'Engine' trait for in-place decimation-in-time Inverse Fast Fourier Transform. Similar to FFT, it operates on a data chunk and requires the size to be a power of two. ```rust fn ifft( &self, data: &mut ShardsRefMut<'_>, pos: usize, size: usize, truncated_size: usize, skew_delta: usize, ) ``` -------------------------------- ### Implement CloneToUninit for Generic Type T Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the unstable nightly-only experimental API `clone_to_uninit` for a generic type T, requiring T to implement Clone. This performs copy-assignment to an uninitialized memory location. ```rust impl CloneToUninit for T where T: Clone, unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### Implement ExactSizeIterator for RestoredOriginal in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct Implements the `ExactSizeIterator` trait for the `RestoredOriginal` struct. This provides methods to determine the exact remaining length and emptiness of the iterator. Note that `is_empty` is a nightly-only experimental API. ```rust impl ExactSizeIterator for RestoredOriginal<'_> 1.0.0 · Source§ #### fn len(&self) -> usize Returns the exact remaining length of the iterator. Read more Source§ #### fn is_empty(&self) -> bool 🔬This is a nightly-only experimental API. (`exact_size_is_empty`) Returns `true` if the iterator is empty. Read more Source§ ``` -------------------------------- ### Implement RateEncoder for LowRateEncoder in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/struct Implements the RateEncoder trait for the LowRateEncoder struct. This provides methods for managing Reed-Solomon encoding rates, including adding original shards, encoding data, converting to parts, creating new encoders, resetting parameters, checking support, and validating configurations. ```rust impl RateEncoder for LowRateEncoder { type Rate = LowRate; fn add_original_shard>(&mut self, original_shard: T) -> Result<(), Error>; fn encode(&mut self) -> Result, Error>; fn into_parts(self) -> (E, EncoderWork); fn new( original_count: usize, recovery_count: usize, shard_bytes: usize, engine: E, work: Option, ) -> Result; fn reset( &mut self, original_count: usize, recovery_count: usize, shard_bytes: usize, ) -> Result<(), Error>; fn supports(original_count: usize, recovery_count: usize) -> bool; fn validate( original_count: usize, recovery_count: usize, shard_bytes: usize, ) -> Result<(), Error>; } ``` -------------------------------- ### Implement Iterator for RestoredOriginal in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct Implements the core `Iterator` trait for the `RestoredOriginal` struct. This allows iteration over the restored shards and their indexes. It includes methods like `next`, `size_hint`, `next_chunk`, `count`, `last`, `advance_by`, `nth`, `step_by`, `chain`, `zip`, `intersperse`, `intersperse_with`, `map`, `for_each`, `filter`, `filter_map`, `enumerate`, `peekable`, `skip_while`, and `take_while`. ```rust impl<'a> Iterator for RestoredOriginal<'a> Source§ #### type Item = (usize, &'a [u8]) The type of the elements being iterated over. Source§ #### fn next(&mut self) -> Option<(usize, &'a [u8])> Advances the iterator and returns the next value. Read more Source§ #### fn size_hint(&self) -> (usize, Option) Returns the bounds on the remaining length of the iterator. Read more Source§ #### fn next_chunk( &mut self, ) -> Result<[Self::Item; N], IntoIter> where Self: Sized, 🔬This is a nightly-only experimental API. (`iter_next_chunk`) Advances the iterator and returns an array containing the next `N` values. Read more 1.0.0 · Source§ #### fn count(self) -> usize where Self: Sized, Consumes the iterator, counting the number of iterations and returning it. Read more 1.0.0 · Source§ #### fn last(self) -> Option where Self: Sized, Consumes the iterator, returning the last element. Read more Source§ #### fn advance_by(&mut self, n: usize) -> Result<(), NonZero> 🔬This is a nightly-only experimental API. (`iter_advance_by`) Advances the iterator by `n` elements. Read more 1.0.0 · Source§ #### fn nth(&mut self, n: usize) -> Option Returns the `n`th element of the iterator. Read more 1.28.0 · Source§ #### fn step_by(self, step: usize) -> StepBy where Self: Sized, Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more 1.0.0 · Source§ #### fn chain(self, other: U) -> Chain::IntoIter> where Self: Sized, U: IntoIterator, Takes two iterators and creates a new iterator over both in sequence. Read more 1.0.0 · Source§ #### fn zip(self, other: U) -> Zip::IntoIter> where Self: Sized, U: IntoIterator, ‘Zips up’ two iterators into a single iterator of pairs. Read more Source§ #### fn intersperse(self, separator: Self::Item) -> Intersperse where Self: Sized, Self::Item: Clone, 🔬This is a nightly-only experimental API. (`iter_intersperse`) Creates a new iterator which places a copy of `separator` between adjacent items of the original iterator. Read more Source§ #### fn intersperse_with(self, separator: G) -> IntersperseWith where Self: Sized, G: FnMut() -> Self::Item, 🔬This is a nightly-only experimental API. (`iter_intersperse`) Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. Read more 1.0.0 · Source§ #### fn map(self, f: F) -> Map where Self: Sized, F: FnMut(Self::Item) -> B, Takes a closure and creates an iterator which calls that closure on each element. Read more 1.21.0 · Source§ #### fn for_each(self, f: F) where Self: Sized, F: FnMut(Self::Item), Calls a closure on each element of an iterator. Read more 1.0.0 · Source§ #### fn filter

(self, predicate: P) -> Filter where Self: Sized, P: FnMut(&Self::Item) -> bool, Creates an iterator which uses a closure to determine if an element should be yielded. Read more 1.0.0 · Source§ #### fn filter_map(self, f: F) -> FilterMap where Self: Sized, F: FnMut(Self::Item) -> Option, Creates an iterator that both filters and maps. Read more 1.0.0 · Source§ #### fn enumerate(self) -> Enumerate where Self: Sized, Creates an iterator which gives the current iteration count as well as the next value. Read more 1.0.0 · Source§ #### fn peekable(self) -> Peekable where Self: Sized, Creates an iterator which can use the `peek` and `peek_mut` methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more 1.0.0 · Source§ #### fn skip_while

(self, predicate: P) -> SkipWhile where Self: Sized, P: FnMut(&Self::Item) -> bool, Creates an iterator that `skip`s elements based on a predicate. Read more 1.0.0 · Source§ #### fn take_while

(self, predicate: P) -> TakeWhile where Self: Sized, P: FnMut(&Self::Item) -> bool, Creates an iterator that yields elements based on a predicate. Read more 1.57.0 · Source§ ``` -------------------------------- ### Reed-Solomon SIMD Engine Evaluate Polynomial Method (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/trait Implements the 'eval_poly' method within the 'Engine' trait for evaluating a polynomial. This is a provided method, meaning it has a default implementation that can be overridden if needed. ```rust fn eval_poly(erasures: &mut [GfElement; 65536], truncated_size: usize) where Self: Sized { ... } ``` -------------------------------- ### High Rate Encoding Algorithm Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/algorithm/index Details the algorithm for high rate encoding in Reed-Solomon codes. Encoding is performed in chunks determined by the next power of two of the recovery count. Original shards are chunked and potentially padded. Recovery shards are generated by applying FFT to the XOR sum of IFFTs of the original chunks, each potentially with a unique skew. ```text recovery_chunk = FFT( IFFT(original_chunk_0, skew_0) xor IFFT(original_chunk_1, skew_1) xor ... ) ``` -------------------------------- ### Auto Trait Implementations for ShardsRefMut in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Showcases the auto trait implementations for `ShardsRefMut`, indicating its safety and thread-safety characteristics. These include `Freeze`, `RefUnwindSafe`, `Send`, `Sync`, `Unpin`, and the explicit `!UnwindSafe` implementation, which are crucial for understanding its behavior in concurrent and exception-handling scenarios. ```rust impl<'a> Freeze for ShardsRefMut<'a> impl<'a> RefUnwindSafe for ShardsRefMut<'a> impl<'a> Send for ShardsRefMut<'a> impl<'a> Sync for ShardsRefMut<'a> impl<'a> Unpin for ShardsRefMut<'a> impl<'a> !UnwindSafe for ShardsRefMut<'a> ``` -------------------------------- ### Reed-Solomon SIMD Engine Trait Definition (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/trait Defines the 'Engine' trait, which outlines the required and provided methods for Reed-Solomon encoding and decoding algorithms. This trait is intended to be implemented by different SIMD-optimized CPU architectures. ```rust pub trait Engine { // Required methods fn fft( &self, data: &mut ShardsRefMut<'_>, pos: usize, size: usize, truncated_size: usize, skew_delta: usize, ); fn ifft( &self, data: &mut ShardsRefMut<'_>, pos: usize, size: usize, truncated_size: usize, skew_delta: usize, ); fn mul(&self, x: &mut [[u8; 64]], log_m: GfElement); // Provided method fn eval_poly(erasures: &mut [GfElement; 65536], truncated_size: usize) where Self: Sized { ... } } ``` -------------------------------- ### Encode Data with Reed-Solomon Algorithm (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/fn The `encode` function takes the original shard count, recovery shard count, and the original data shards as input. It returns a `Result` containing a vector of vectors of bytes representing the generated recovery shards or an `Error` if encoding fails. The original data must be convertible into an iterator of byte slices. ```rust pub fn encode( original_count: usize, recovery_count: usize, original: T, ) -> Result>, Error> where T: IntoIterator, T::Item: AsRef<[u8]>, { // ... implementation details ... } ``` -------------------------------- ### RestoredOriginal Struct Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct An iterator over restored original shards and their indexes. This struct is created by `DecoderResult::restored_original_iter`. ```APIDOC ## Struct RestoredOriginal ### Description Iterator over restored original shards and their indexes. This struct is created by `DecoderResult::restored_original_iter`. ### Fields (Private fields, not exposed for direct manipulation) ### Usage Example ```rust // Assuming decoder_result is an instance of DecoderResult // let restored_iter = decoder_result.restored_original_iter(); // for (index, shard) in restored_iter { // println!("Shard index: {}, Data: {:?}", index, shard); // } ``` ``` -------------------------------- ### DefaultRateEncoder Implementation Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/trait An implementation of the RateEncoder trait for a default rate configuration. It leverages the associated `DefaultRate` type for rate-specific operations. ```rust impl RateEncoder for DefaultRateEncoder { type Rate = DefaultRate; // ... implementation details ... } ``` -------------------------------- ### RateEncoder Trait Definition Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/trait Defines the core interface for Reed-Solomon encoders that operate at a specific rate. It requires methods for adding original shards, encoding data, consuming the encoder into its components, creating a new encoder, and resetting its state. It also provides default implementations for checking support and validating parameters. ```rust pub trait RateEncoder where Self: Sized, { type Rate: Rate; // Required methods fn add_original_shard>( &mut self, original_shard: T, ) -> Result<(), Error>; fn encode(&mut self) -> Result, Error>; fn into_parts(self) -> (E, EncoderWork); fn new( original_count: usize, recovery_count: usize, shard_bytes: usize, engine: E, work: Option, ) -> Result; fn reset( &mut self, original_count: usize, recovery_count: usize, shard_bytes: usize, ) -> Result<(), Error>; // Provided methods fn supports(original_count: usize, recovery_count: usize) -> bool { ... } fn validate( original_count: usize, recovery_count: usize, shard_bytes: usize, ) -> Result<(), Error> { ... } } ``` -------------------------------- ### Implement TryFrom and TryInto for Generic Types Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Defines TryFrom and TryInto trait implementations for generic types T and U. These traits enable fallible conversions between types, returning a Result. ```rust impl TryFrom for T where U: Into, type Error = Infallible The type returned in the event of a conversion error. fn try_from(value: U) -> Result>::Error> Performs the conversion. impl TryInto for T where U: TryFrom, type Error = >::Error The type returned in the event of a conversion error. fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Reed-Solomon SIMD Engine Multiplication Method (Rust) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/trait Implements the 'mul' method within the 'Engine' trait for element-wise multiplication of a byte array by a Galois Field element. This is a core operation for Reed-Solomon error correction. ```rust fn mul(&self, x: &mut [[u8; 64]], log_m: GfElement) ``` -------------------------------- ### Implement StructuralPartialEq for Error Type Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the StructuralPartialEq trait for the Error type, enabling structural comparison of its values. ```rust impl StructuralPartialEq for Error ``` -------------------------------- ### Test for Inequality (ne) Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum The `ne` function tests for inequality (`!=`). The default implementation is usually sufficient and should only be overridden if absolutely necessary. ```rust fn ne(&self, other: &Rhs) -> bool Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. ``` -------------------------------- ### Access Mutable Shards with Distance in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/struct Provides mutable references to shards at a specified position and a position offset by `dist`. The `dist2_mut` function returns references to two shards, while `dist4_mut` returns references to four shards. Both functions panic if `dist` is 0, as this would imply accessing the same shard multiple times in an invalid way. ```rust pub fn dist2_mut( &mut self, pos: usize, dist: usize, ) -> (&mut [[u8; 64]], &mut [[u8; 64]]) pub fn dist4_mut( &mut self, pos: usize, dist: usize, ) -> (&mut [[u8; 64]], &mut [[u8; 64]], &mut [[u8; 64]], &mut [[u8; 64]]) ``` -------------------------------- ### Implement Auto-Traits for LowRateEncoder in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/struct Applies standard Rust auto-traits to the LowRateEncoder struct, ensuring compatibility with various threading and safety mechanisms. This includes Freeze, RefUnwindSafe, Send, Sync, Unpin, and UnwindSafe. ```rust impl Freeze for LowRateEncoder where E: Freeze, impl RefUnwindSafe for LowRateEncoder where E: RefUnwindSafe, impl Send for LowRateEncoder where E: Send, impl Sync for LowRateEncoder where E: Sync, impl Unpin for LowRateEncoder where E: Unpin, impl UnwindSafe for LowRateEncoder where E: UnwindSafe ``` -------------------------------- ### LowRateEncoder Implementation Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/trait An implementation of the RateEncoder trait for a low rate configuration. It utilizes the associated `LowRate` type for its rate-dependent functionalities. ```rust impl RateEncoder for LowRateEncoder { type Rate = LowRate; // ... implementation details ... } ``` -------------------------------- ### Implement Display and ToString for Error Type Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Provides the Display and ToString trait implementations for the Error type, allowing it to be converted into a String representation. This is useful for logging or debugging purposes. ```rust impl ToString for T where T: Display + ?Sized, fn to_string(&self) -> String Converts the given value to a `String`. Read more ``` -------------------------------- ### Implement From for Generic Type T Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Provides a generic implementation of the From trait for type T, where T can be created from itself. This is a common identity conversion. ```rust impl From for T fn from(t: T) -> T Returns the argument unchanged. ``` -------------------------------- ### Implement Clone for Multiply128lutT Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/tables/struct Provides implementations for the Clone trait, allowing instances of Multiply128lutT to be duplicated. This is crucial for managing and passing around table data without unintended modifications. ```rust impl Clone for Multiply128lutT { fn clone(&self) -> Multiply128lutT { // ... implementation details ... } fn clone_from(&mut self, source: &Self) { // ... implementation details ... } } ``` -------------------------------- ### Implement Borrow and BorrowMut for Generic Type T Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Provides implementations for Borrow and BorrowMut traits on a generic type T. These traits allow for immutable and mutable borrowing of owned values, respectively. ```rust impl Borrow for T where T: ?Sized, fn borrow(&self) -> &T Immutably borrows from an owned value. Read more impl BorrowMut for T where T: ?Sized, fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. Read more ``` -------------------------------- ### HighRateEncoder Implementation Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/trait An implementation of the RateEncoder trait for a high rate configuration. It uses the associated `HighRate` type for its rate-specific logic. ```rust impl RateEncoder for HighRateEncoder { type Rate = HighRate; // ... implementation details ... } ``` -------------------------------- ### Implement Debug for Multiply128lutT Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/engine/tables/struct Implements the Debug trait for Multiply128lutT, enabling formatted output for debugging purposes. This is useful for inspecting the contents of the multiplication tables during development and testing. ```rust impl Debug for Multiply128lutT { fn fmt(&self, f: &mut Formatter<'_>) -> Result { // ... implementation details ... } } ``` -------------------------------- ### Implement Into for Generic Types T and U Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the Into trait for converting a type T into a type U, provided that U implements From. This enables convenient conversions using the into() method. ```rust impl Into for T where U: From, fn into(self) -> U Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ``` -------------------------------- ### Implement Copy for Error Type Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the Copy trait for the Error type. This allows instances of Error to be copied implicitly. ```rust impl Copy for Error ``` -------------------------------- ### Reed-Solomon-SIMD Error Enum Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum The `Error` enum represents all possible errors that can occur within the reed-solomon-simd library. It includes variants for issues related to shard size, duplicate shard indices, invalid shard indices, insufficient or excessive shards, and unsupported shard count combinations. ```APIDOC ## Enum Error ### Description Represents all possible errors that can occur in this library. ### Variants #### DifferentShardSize Given shard has different size than given or inferred shard size. * Shard size is given explicitly to encoders/decoders and inferred for `reed_solomon_simd::encode` and `reed_solomon_simd::decode`. ##### Fields * `shard_bytes` (usize) - Given or inferred shard size. * `got` (usize) - Size of the given shard. #### DuplicateOriginalShardIndex Decoder was given two original shards with same index. ##### Fields * `index` (usize) - Given duplicate index. #### DuplicateRecoveryShardIndex Decoder was given two recovery shards with same index. ##### Fields * `index` (usize) - Given duplicate index. #### InvalidOriginalShardIndex Decoder was given original shard with invalid index, i.e. `index >= original_count`. ##### Fields * `original_count` (usize) - Configured number of original shards. * `index` (usize) - Given invalid index. #### InvalidRecoveryShardIndex Decoder was given recovery shard with invalid index, i.e. `index >= recovery_count`. ##### Fields * `recovery_count` (usize) - Configured number of recovery shards. * `index` (usize) - Given invalid index. #### InvalidShardSize Given or inferred shard size is invalid: Size must be non-zero and even. * Shard size is given explicitly to encoders/decoders and inferred for `reed_solomon_simd::encode` and `reed_solomon_simd::decode`. ##### Fields * `shard_bytes` (usize) - Given or inferred shard size. #### NotEnoughShards Decoder was given too few shards. Decoding requires as many shards as there were original shards in total, in any combination of original shards and recovery shards. ##### Fields * `original_count` (usize) - Configured number of original shards. * `original_received_count` (usize) - Number of original shards given to decoder. * `recovery_received_count` (usize) - Number of recovery shards given to decoder. #### TooFewOriginalShards Encoder was given less than `original_count` original shards. ##### Fields * `original_count` (usize) - Configured number of original shards. * `original_received_count` (usize) - Number of original shards given to encoder. #### TooManyOriginalShards Encoder was given more than `original_count` original shards. ##### Fields * `original_count` (usize) - Configured number of original shards. #### UnsupportedShardCount Given `original_count` / `recovery_count` combination is not supported. ##### Fields * `original_count` (usize) - Given number of original shards. * `recovery_count` (usize) - Given number of recovery shards. ``` -------------------------------- ### Implement Any for Generic Type T Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the Any trait for a generic type T. This allows for downcasting and runtime type information. ```rust impl Any for T where T: 'static + ?Sized, ``` -------------------------------- ### Implement Clone and ToOwned for Generic Type T Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Implements the Clone and ToOwned traits for a generic type T, provided T itself implements Clone. This allows for creating owned copies of borrowed data. ```rust impl ToOwned for T where T: Clone, type Owned = T The resulting type after obtaining ownership. fn to_owned(&self) -> T Creates owned data from borrowed data, usually by cloning. Read more fn clone_into(&self, target: &mut T) Uses borrowed data to replace owned data, usually by cloning. Read more ``` -------------------------------- ### Implement Sync Auto Trait for Error Type Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/enum Marks the Error type as implementing the Sync auto trait, indicating it is safe to be referenced across threads. ```rust impl Sync for Error ``` -------------------------------- ### Define RestoredOriginal Struct in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/struct Defines the `RestoredOriginal` struct, an iterator over restored original shards and their indexes. This struct is typically created by the `DecoderResult::restored_original_iter` method. It is a private struct, indicated by '/* private fields */'. ```rust pub struct RestoredOriginal<'a> { /* private fields */ } ``` -------------------------------- ### Define LowRateEncoder Struct in Rust Source: https://docs.rs/reed-solomon-simd/latest/reed_solomon_simd/rate/struct Defines the LowRateEncoder struct, which uses a generic 'Engine' type. This struct is designed for Reed-Solomon encoding with a low rate. It contains private fields. ```rust pub struct LowRateEncoder { /* private fields */ } ```