Skip to main content

erasure_isa_l/
lib.rs

1mod bind;
2pub mod erasure;
3pub mod galois;
4
5pub use bind::ec;
6pub use bind::gf;
7
8/// The `Error` enum defines the possible errors that this crate can occur.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// TooManyErasure: The number of erasures is larger than the maximum allowed,
12    /// and the lost data cannot be recovered.
13    #[error("Too Many Erased Blocks: {0} erased, up to {1} allowed")]
14    TooManyErasures(usize, usize),
15    /// InvalidArguments: The the input is invalid.
16    #[error("Invalid Arguments: {0}")]
17    InvalidArguments(String),
18    /// InternalError: An internal error caused by libisa-l.
19    #[error("Internal Error: {0}")]
20    InternalError(String),
21    /// Other: Other errors that are not covered by the above.
22    #[error("Error: {0}")]
23    Other(String),
24}
25
26#[allow(dead_code)]
27impl Error {
28    fn too_many_erasures(erasures: usize, max_erasures: usize) -> Self {
29        Self::TooManyErasures(erasures, max_erasures)
30    }
31
32    fn invalid_arguments(msg: impl Into<String>) -> Self {
33        Self::InvalidArguments(msg.into())
34    }
35
36    fn internal_error(msg: impl Into<String>) -> Self {
37        Self::InternalError(msg.into())
38    }
39
40    fn other(msg: impl Into<String>) -> Self {
41        Self::Other(msg.into())
42    }
43}