Struct liberasurecode::ErasureCoder[][src]

pub struct ErasureCoder { /* fields omitted */ }

Erasure coder.

Examples

use liberasurecode::{ErasureCoder, Error};
use std::num::NonZeroUsize;

let data_fragments = NonZeroUsize::new(4).ok_or("too few fragments")?;
let parity_fragments = NonZeroUsize::new(2).ok_or("too few fragments")?;
let mut coder = ErasureCoder::new(data_fragments, parity_fragments)?;
let data = vec![0, 1, 2, 3];
let encoded = coder.encode(&data)?;

assert_eq!(Ok(&data), coder.decode(&encoded[0..]).as_ref());
assert_eq!(Ok(&data), coder.decode(&encoded[1..]).as_ref());
assert_eq!(Ok(&data), coder.decode(&encoded[2..]).as_ref());
assert_eq!(Err(Error::InsufficientFragments),
           coder.decode(&encoded[3..]));

Methods

impl ErasureCoder
[src]

Makes a new ErasureCoder instance with the default settings.

This is equivalent to Builder::new(data_fragments, parity_fragments).finish().

Returns the number of data fragments specified to the coder.

Returns the number of parity fragments specified to the coder.

The total number of data fragments and parity fragments specified to the coder.

Encodes the given data to data and parity fragments.

Decodes the original data from the given fragments.

Reconstructs the fragment specified by the given index from other available fragments.

Trait Implementations

impl Debug for ErasureCoder
[src]

Formats the value using the given formatter. Read more

impl Drop for ErasureCoder
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations