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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mod ffi;
mod plugin;
use std::{
error::Error as StdError,
fmt::{ Display, Formatter, Result as FmtResult },
io::{ Error as IoError, ErrorKind as IoErrorKind }
};
pub use crate::{ plugin::{ Plugin, FormatUid }, ffi::{ CSlice, AsCSlice, AsCSliceMut } };
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ErrorKind {
InitializationError,
BufferError{ required_size: usize },
PermissionDenied{ requires_authentication: bool },
AccessDenied{ retries_left: Option<u64> },
IoError,
InvalidData,
NoKeyAvailable,
OperationCancelled,
OperationTimedOut,
OtherPluginError{ errno: u64 },
Unsupported
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct KyncError {
pub kind: ErrorKind,
pub desc: Option<String>
}
impl Display for KyncError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{:?}", &self.kind)?;
if let Some(desc) = self.desc.as_ref() { write!(f, " ({:#?})", desc)?; }
Ok(())
}
}
impl From<ErrorKind> for KyncError {
fn from(kind: ErrorKind) -> Self {
Self{ kind, desc: None }
}
}
impl<T: ToString> From<(ErrorKind, T)> for KyncError {
fn from(kind_desc: (ErrorKind, T)) -> Self {
Self{ kind: kind_desc.0, desc: Some(kind_desc.1.to_string()) }
}
}
impl From<IoErrorKind> for KyncError {
fn from(io_error_kind: IoErrorKind) -> Self {
Self{ kind: ErrorKind::IoError, desc: Some(format!("{:#?}", io_error_kind)) }
}
}
impl From<IoError> for KyncError {
fn from(io_error: IoError) -> Self {
Self{ kind: ErrorKind::IoError, desc: Some(format!("{}", io_error)) }
}
}
impl StdError for KyncError {}