[][src]Struct liberasurecode::ErasureCoder

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]

pub fn new(
    data_fragments: NonZeroUsize,
    parity_fragments: NonZeroUsize
) -> Result<Self>
[src]

Makes a new ErasureCoder instance with the default settings.

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

pub fn data_fragments(&self) -> NonZeroUsize[src]

Returns the number of data fragments specified to the coder.

pub fn parity_fragments(&self) -> NonZeroUsize[src]

Returns the number of parity fragments specified to the coder.

pub fn fragments(&self) -> NonZeroUsize[src]

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

pub fn encode(&mut self, data: &[u8]) -> Result<Vec<Vec<u8>>>[src]

Encodes the given data to data and parity fragments.

pub fn decode<T: AsRef<[u8]>>(&mut self, fragments: &[T]) -> Result<Vec<u8>>[src]

Decodes the original data from the given fragments.

pub fn reconstruct<T, F>(
    &mut self,
    index: usize,
    available_fragments: T
) -> Result<Vec<u8>> where
    T: Iterator<Item = F>,
    F: AsRef<[u8]>, 
[src]

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

Errors

This function will return Error::InvalidParams if the given index is bigger or equal than the total number of parity_fragments and data_fragments.

Trait Implementations

impl Drop for ErasureCoder[src]

impl Debug for ErasureCoder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]