[][src]Crate liberasurecode

A Rust wrapper for openstack/liberasurecode.

Prerequisites to Build

This crate requires the following packages for building openstack/liberasurecode in the build script:

  • C compiler (e.g., gcc)
  • git
  • make
  • automake
  • autoconf
  • libtool

For example, on Ubuntu, you can install those by executing the following command:

$ sudo apt install gcc git make automake autoconf libtool

Examples

Basic usage:

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 input = vec![0, 1, 2, 3];

// Encodes `input` to data and parity fragments
let fragments = coder.encode(&input)?;

// Decodes the original data from the fragments (or a part of those)
assert_eq!(Ok(&input), coder.decode(&fragments[0..]).as_ref());
assert_eq!(Ok(&input), coder.decode(&fragments[1..]).as_ref());
assert_eq!(Ok(&input), coder.decode(&fragments[2..]).as_ref());
assert_eq!(Err(Error::InsufficientFragments), coder.decode(&fragments[3..]));

Structs

Builder

ErasureCoder builder.

ErasureCoder

Erasure coder.

Enums

Backend

Erasure coding backends that can be used for encoding and decoding data.

Checksum

Available checksum algorithms for validating decoded data.

Error

Possible errors.

Type Definitions

Result

This crate specific Result type.