-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror.rs
62 lines (52 loc) · 1.58 KB
/
error.rs
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
use thiserror::Error;
use crate::split::ProportionSplit;
/// Error type in ttv.
#[derive(Debug, Error)]
pub enum Error {
#[error("empty file")]
EmptyFile,
#[error("invalid split specification: {0}")]
InvalidSplitSpecification(String),
#[error("invalid splits: {0:?}")]
InvalidSplits(Vec<ProportionSplit>),
#[error("proportion too low: {0}")]
ProportionTooLow(String),
#[error("proportion too high: {0}")]
ProportionTooHigh(String),
#[error("error parsing CSV: {0}")]
CsvError(csv::Error),
#[error("I/O error: {0}")]
IoError(std::io::Error),
#[error("error parsing float: {0}")]
ParseFloatError(std::num::ParseFloatError),
#[error("error parsing int: {0}")]
ParseIntError(std::num::ParseIntError),
#[error("internal error: {0}")]
SendError(std::sync::mpsc::SendError<String>),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<std::num::ParseFloatError> for Error {
fn from(error: std::num::ParseFloatError) -> Self {
Error::ParseFloatError(error)
}
}
impl From<std::num::ParseIntError> for Error {
fn from(error: std::num::ParseIntError) -> Self {
Error::ParseIntError(error)
}
}
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Error::IoError(error)
}
}
impl From<csv::Error> for Error {
fn from(error: csv::Error) -> Self {
Error::CsvError(error)
}
}
impl From<std::sync::mpsc::SendError<String>> for Error {
fn from(error: std::sync::mpsc::SendError<String>) -> Self {
Error::SendError(error)
}
}