1use std::convert::From;
4use std::error::Error;
5use std::fmt;
6
7pub type Result<T> = ::std::result::Result<T, FtpError>;
9
10#[derive(Debug)]
13pub enum FtpError {
14 ConnectionError(::std::io::Error),
15 SecureError(String),
16 InvalidResponse(String),
17 InvalidAddress(::std::net::AddrParseError),
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
22pub enum FormatControl {
23 Default,
25 NonPrint,
27 Telnet,
29 Asa,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
35pub enum FileType {
36 Ascii(FormatControl),
38 Ebcdic(FormatControl),
40 Image,
42 Binary,
44 Local(u8),
46}
47
48pub struct Line(pub u32, pub String);
50
51impl ToString for FormatControl {
52 fn to_string(&self) -> String {
53 match self {
54 &FormatControl::Default | &FormatControl::NonPrint => String::from("N"),
55 &FormatControl::Telnet => String::from("T"),
56 &FormatControl::Asa => String::from("C"),
57 }
58 }
59}
60
61impl ToString for FileType {
62 fn to_string(&self) -> String {
63 match self {
64 &FileType::Ascii(ref fc) => format!("A {}", fc.to_string()),
65 &FileType::Ebcdic(ref fc) => format!("E {}", fc.to_string()),
66 &FileType::Image | &FileType::Binary => String::from("I"),
67 &FileType::Local(ref bits) => format!("L {}", bits),
68 }
69 }
70}
71
72impl fmt::Display for FtpError {
73 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74 match *self {
75 FtpError::ConnectionError(ref ioerr) => write!(f, "FTP ConnectionError: {}", ioerr),
76 FtpError::SecureError(ref desc) => write!(f, "FTP SecureError: {}", desc.clone()),
77 FtpError::InvalidResponse(ref desc) => {
78 write!(f, "FTP InvalidResponse: {}", desc.clone())
79 }
80 FtpError::InvalidAddress(ref perr) => write!(f, "FTP InvalidAddress: {}", perr),
81 }
82 }
83}
84
85impl Error for FtpError {
86 fn cause(&self) -> Option<&dyn Error> {
87 match *self {
88 FtpError::ConnectionError(ref ioerr) => Some(ioerr),
89 FtpError::SecureError(_) => None,
90 FtpError::InvalidResponse(_) => None,
91 FtpError::InvalidAddress(ref perr) => Some(perr),
92 }
93 }
94}