1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! This crate provides thread pool([`ErasureCoderPool`]) for managing executions of erasure coding.
//!
//! `ecpool` also provides [`ErasureCode`] trait defines erasure coding interface
//! and of which implemtations can be executed via [`ErasureCoderPool`].
//!
//! There are some built-in implementations of the trait:
//! - [`LibErasureCoder`]:
//! - This implementation uses [`liberasurecode`] crate that is a wrapper for [openstack/liberasurecode] library.
//! - It is highly optimized and stable but only available in Unix environments.
//! - [`ReplicaCoder`]:
//! - This implementation simply replicates the input data.
//! - It is provided for example and testing purposes only and not intended to use in production.
//!
//!
//! # Build Prerequisites
//!
//! It is required to install [openstack/liberasurecode] and its dependencies by executing
//! the following commands before building this crate:
//!
//! ```console
//! $ git clone https://github.com/frugalos/liberasurecode
//! $ cd liberasurecode && sudo ./install_deps.sh
//! ```
//!
//! # Examples
//!
//! Basic usage:
//! ```
//! # extern crate ecpool;
//! # extern crate fibers_global;
//! # extern crate trackable;
//! use ecpool::replica::ReplicaCoder;
//! use ecpool::{ErrorKind, ErasureCoderPool};
//! use std::num::NonZeroUsize;
//! use std::result::Result;
//! use trackable::error::{Failure, Failed};
//!
//! # fn main() -> Result<(), trackable::error::MainError> {
//! // Creates a pool
//! let data_fragments = NonZeroUsize::new(4).ok_or_else(|| Failure::from(Failed))?;
//! let parity_fragments = NonZeroUsize::new(2).ok_or_else(|| Failure::from(Failed))?;
//! let coder = ErasureCoderPool::new(ReplicaCoder::new(data_fragments, parity_fragments));
//!
//! // Encodes
//! let data = vec![0, 1, 2, 3];
//! let encoded = fibers_global::execute(coder.encode(data.clone()))?;
//!
//! // Decodes
//! assert_eq!(
//! Some(&data),
//! fibers_global::execute(coder.decode(encoded[0..].to_vec()))
//! .as_ref()
//! .ok()
//! );
//! assert_eq!(
//! Some(&data),
//! fibers_global::execute(coder.decode(encoded[1..].to_vec()))
//! .as_ref()
//! .ok()
//! );
//! assert_eq!(
//! Some(&data),
//! fibers_global::execute(coder.decode(encoded[2..].to_vec()))
//! .as_ref()
//! .ok()
//! );
//! assert_eq!(
//! Err(ErrorKind::InvalidInput),
//! fibers_global::execute(coder.decode(encoded[3..].to_vec())).map_err(|e| *e.kind())
//! );
//! # Ok(())
//! # }
//! ```
//!
//! [`ErasureCoderPool`]: ./struct.ErasureCoderPool.html
//! [`ErasureCode`]: ./trait.ErasureCode.html
//! [`liberasurecode`]: https://github.com/frugalos/liberasurecode
//! [openstack/liberasurecode]: https://github.com/openstack/liberasurecode
//! [`LibErasureCoder`]: ./liberasurecode/struct.LibErasureCoder.html
//! [`ReplicaCoder`]: ./replica/struct.ReplicaCoder.html
extern crate fibers;
extern crate fibers_global;
extern crate fibers_tasque;
extern crate futures;
extern crate trackable;
extern crate liberasurecode as libec;
use NonZeroUsize;
pub use ;
pub use ErasureCoderPool;
/// This crate specific [`Result`] type.
///
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
pub type Result<T> = Result;
/// A fragment.
pub type Fragment = ;
/// An owned fragment.
pub type FragmentBuf = ;
/// This trait allows for encoding and decoding data by using some erasure coding algorithm.
/// This trait allows for building instances of an implementaion of [`ErasureCode`] trait.
///
/// [`ErasureCode`]: ./trait.ErasureCode.html