Struct ecpool::replica::ReplicaCoder[][src]

pub struct ReplicaCoder { /* fields omitted */ }

An ErasureCode implementation that simply replicates the input data.

Note that this is provided for example and testing purposes only and not intended to use in production.

Examples

use ecpool::{ErasureCode, ErrorKind};
use ecpool::replica::ReplicaCoder;
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 = ReplicaCoder::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 ReplicaCoder
[src]

Makes a new ReplicaCoder instance.

Trait Implementations

impl Debug for ReplicaCoder
[src]

Formats the value using the given formatter. Read more

impl Clone for ReplicaCoder
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl ErasureCode for ReplicaCoder
[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

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

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

impl BuildCoder for ReplicaCoder
[src]

The type of ErasureCode implementaion to be built.

Builds an instance of the ErasureCode implementaion.

Returns the identifier that distinguishes the kind of instances to be built. Read more

Auto Trait Implementations