-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
53 lines (46 loc) · 1.74 KB
/
Copy patherror.rs
File metadata and controls
53 lines (46 loc) · 1.74 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
52
53
use std::{fmt::Display, io::ErrorKind};
use crate::command::CommandParseErr;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Clone, Debug)]
pub enum Error {
Command(CommandParseErr),
IO(ErrorKind),
CannotQuitWithUnsavedBuffer,
WriteParentDirectoryDoesntExist,
MoveParentDirectoryDoesntExist,
NoPathSet
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Command(command_parse_err) => match command_parse_err {
CommandParseErr::TooManyArgs => f.write_str("Too many arguments"),
CommandParseErr::NotEnoughArgs => f.write_str("Not enough arguments"),
CommandParseErr::Unknown => f.write_str("Unknown command"),
CommandParseErr::CannotParse => f.write_str("Cannot parse command")
},
Error::IO(error_kind) => write!(f, "IO error: {error_kind}"),
Error::CannotQuitWithUnsavedBuffer => {
f.write_str("Cannot quit with unsaved buffer, use q! to override")
}
Error::WriteParentDirectoryDoesntExist => {
f.write_str("Parent directory doesn't exist, use w! to create")
}
Error::MoveParentDirectoryDoesntExist => {
f.write_str("Parent directory doesn't exist, use mv! to create")
}
Error::NoPathSet => f.write_str("Cannot write with no path set")
}
}
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Self::IO(err.kind())
}
}
impl From<CommandParseErr> for Error {
fn from(err: CommandParseErr) -> Self {
Self::Command(err)
}
}