-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr.rs
More file actions
46 lines (41 loc) · 1.14 KB
/
Copy patherr.rs
File metadata and controls
46 lines (41 loc) · 1.14 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
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::io;
#[derive(Debug)]
pub enum LoadErr {
CantReadFile,
Invalid,
BufferTooShort,
IO(io::Error),
}
impl From<io::Error> for LoadErr {
fn from(err: io::Error) -> Self {
if err.kind() == io::ErrorKind::UnexpectedEof {
Self::BufferTooShort
} else {
Self::IO(err)
}
}
}
impl Display for LoadErr {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl Error for LoadErr {}
// This should be a different enum per part of file. Either return a list of these or take a callback
// TODO: https://users.rust-lang.org/t/validation-monad/117894/6
//
// load was partially successful. These are the defects that are in the now loaded project
// #[derive(Debug, Clone, Copy)]
// #[non_exhaustive]
// pub enum LoadDefect {
// /// deletes the effect
// UnknownEffect,
// /// replaced with empty text
// InvalidText,
// /// tries to replace with a sane default value
// OutOfBoundsValue,
// /// skips loading of the pointed to value
// OutOfBoundsPtr,
// }