forked from DimaKudosh/word2vec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
51 lines (45 loc) · 1.36 KB
/
errors.rs
File metadata and controls
51 lines (45 loc) · 1.36 KB
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
use std::error;
use std::fmt;
use std::io;
use std::string::FromUtf8Error;
/// Common error type for errors concerning loading and processing binary word vectors
///
/// This error type mostly wraps I/O and encoding errors, but also adds crate-specific error
/// variants.
#[derive(Debug)]
pub enum Word2VecError {
Io(io::Error),
Decode(FromUtf8Error),
WrongHeader,
}
impl error::Error for Word2VecError {
fn description(&self) -> &str {
unimplemented!("Please use fmt::Display.")
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Word2VecError::Decode(ref e) => e.source(),
Word2VecError::Io(ref e) => e.source(),
_ => None,
}
}
}
impl fmt::Display for Word2VecError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Word2VecError::Io(ref err) => write!(f, "IO error: {}", err),
Word2VecError::Decode(ref err) => write!(f, "Decode error: {}", err),
Word2VecError::WrongHeader => write!(f, "Wrong header length."),
}
}
}
impl From<io::Error> for Word2VecError {
fn from(err: io::Error) -> Word2VecError {
Word2VecError::Io(err)
}
}
impl From<FromUtf8Error> for Word2VecError {
fn from(err: FromUtf8Error) -> Word2VecError {
Word2VecError::Decode(err)
}
}