Struct ecpool::liberasurecode::LibErasureCoder[][src]

pub struct LibErasureCoder { /* fields omitted */ }

An ErasureCode implementation based on openstack/liberasurecode.

Examples

use ecpool::{ErasureCode, ErrorKind};
use ecpool::liberasurecode::LibErasureCoder;
use std::num::NonZeroUsize;

let data_fragments = NonZeroUsize::new(4).ok_or("invalid input")?;
let parity_fragments = NonZeroUsize::new(2).ok_or("invalid input")?;
let mut coder = LibErasureCoder::new(data_fragments, parity_fragments)?;

// Encodes
let data = vec![0, 1, 2, 3];
let encoded = coder.encode(&data)?;
let encoded = encoded.iter().map(|f| f.as_ref()).collect::<Vec<_>>();

// Decodes
assert_eq!(Some(&data), coder.decode(&encoded[0..]).as_ref().ok());
assert_eq!(Some(&data), coder.decode(&encoded[1..]).as_ref().ok());
assert_eq!(Some(&data), coder.decode(&encoded[2..]).as_ref().ok());
assert_eq!(Err(ErrorKind::InvalidInput), coder.decode(&encoded[3..]).map_err(|e| *e.kind()));

Methods

impl LibErasureCoder
[src]

Makes a new LibErasureCoder instance with the default settings.

This is equivalent to LibErasureCoderBuilder::new(data_fragments, parity_fragments).build_coder().

Returns a reference to the inner coder of the instance.

Returns a mutable reference to the inner coder of the instance.

Takes the owership of the instance and returns the inner coder.

Trait Implementations

impl ErasureCode for LibErasureCoder
[src]

Returns the number of data fragments that the instance uses when encoding/decoding data.

Returns the number of parity fragments that the instance uses when encoding/decoding data.

Encodes the given data to fragments. Read more

Decodes the original data from the given fragments. Read more

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

The total number of data fragments and parity fragments of the instance.

impl From<ErasureCoder> for LibErasureCoder
[src]

Performs the conversion.

Auto Trait Implementations