[−][src]Struct liberasurecode::ErasureCoder
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]
data_fragments: NonZeroUsize,
parity_fragments: NonZeroUsize
) -> Result<Self>
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]
&mut self,
index: usize,
available_fragments: T
) -> Result<Vec<u8>> where
T: Iterator<Item = F>,
F: AsRef<[u8]>,
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
impl Unpin for ErasureCoder
impl Send for ErasureCoder
impl Sync for ErasureCoder
impl RefUnwindSafe for ErasureCoder
impl UnwindSafe for ErasureCoder
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,