| 1 | use std::error; |
| 2 | use std::fmt; |
| 3 | use std::result; |
| 4 | use std::string::String; |
| 5 | |
| 6 | #[derive(Debug, Clone, PartialEq)] |
| 7 | pub enum Alignment { |
| 8 | Unspecified, // default Left for strings, Right for numbers |
| 9 | Left, |
| 10 | Center, |
| 11 | Right, |
| 12 | Equal, |
| 13 | } |
| 14 | |
| 15 | #[derive(Debug, Clone, PartialEq)] |
| 16 | pub enum Sign { |
| 17 | Unspecified, |
| 18 | Plus, |
| 19 | Minus, |
| 20 | Space, |
| 21 | } |
| 22 | |
| 23 | impl Sign { |
| 24 | pub fn is_unspecified(&self) -> bool { |
| 25 | match *self { |
| 26 | Sign::Unspecified => false, |
| 27 | _ => true, |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | pub type Result<T> = result::Result<T, FmtError>; |
| 33 | |
| 34 | /// LOC-error |
| 35 | #[derive(Debug, PartialEq)] |
| 36 | pub enum FmtError { |
| 37 | Invalid(String), // format string is structued incorrectly |
| 38 | KeyError(String), // key error in formatting string |
| 39 | TypeError(String), // invalid type used |
| 40 | } |
| 41 | |
| 42 | impl fmt::Display for FmtError { |
| 43 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 44 | match *self { |
| 45 | FmtError::Invalid(ref s) => write!(f, "Invalid({})", s), |
| 46 | FmtError::KeyError(ref s) => write!(f, "KeyError({})", s), |
| 47 | FmtError::TypeError(ref s) => write!(f, "TypeError({})", s), |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl error::Error for FmtError { |
| 53 | fn description(&self) -> &str { |
| 54 | match *self { |
| 55 | FmtError::Invalid(_) => "invalid format string", |
| 56 | FmtError::KeyError(_) => "invalid key", |
| 57 | FmtError::TypeError(_) => "error during type resolution", |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | fn cause(&self) -> Option<&dyn error::Error> { |
| 62 | None |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // enum Type { |
| 67 | // // integer types |
| 68 | // Bin, |
| 69 | // Char, |
| 70 | // Decimal, |
| 71 | // Octal, |
| 72 | // Hex, |
| 73 | // HexUpper, |
| 74 | |
| 75 | // // both |
| 76 | // Number, |
| 77 | |
| 78 | // // Floating point types |
| 79 | // Exponent, |
| 80 | // ExponentUpper, |
| 81 | // Fixed, |
| 82 | // General, |
| 83 | // GeneralUppercase, |
| 84 | // Percengage, |
| 85 | |
| 86 | // // other types |
| 87 | // None, |
| 88 | // String, |
| 89 | // Debug, |
| 90 | // } |