Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/base64ct/src/errors.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / base64ct / src / errors.rs` 81 lines ยท 2116 bytes Raw Blame History 1 //! Error types 2 3 use core::fmt; 4 5 const INVALID_ENCODING_MSG: &str = "invalid Base64 encoding"; 6 const INVALID_LENGTH_MSG: &str = "invalid Base64 length"; 7 8 /// Insufficient output buffer length. 9 #[derive(Copy, Clone, Debug, Eq, PartialEq)] 10 pub struct InvalidLengthError; 11 12 impl fmt::Display for InvalidLengthError { 13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { 14 f.write_str(INVALID_LENGTH_MSG) 15 } 16 } 17 18 impl core::error::Error for InvalidLengthError {} 19 20 /// Invalid encoding of provided Base64 string. 21 #[derive(Copy, Clone, Debug, Eq, PartialEq)] 22 pub struct InvalidEncodingError; 23 24 impl fmt::Display for InvalidEncodingError { 25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { 26 f.write_str(INVALID_ENCODING_MSG) 27 } 28 } 29 30 impl core::error::Error for InvalidEncodingError {} 31 32 /// Generic error, union of [`InvalidLengthError`] and [`InvalidEncodingError`]. 33 #[derive(Copy, Clone, Debug, Eq, PartialEq)] 34 pub enum Error { 35 /// Invalid encoding of provided Base64 string. 36 InvalidEncoding, 37 38 /// Insufficient output buffer length. 39 InvalidLength, 40 } 41 42 impl fmt::Display for Error { 43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { 44 let s = match self { 45 Self::InvalidEncoding => INVALID_ENCODING_MSG, 46 Self::InvalidLength => INVALID_LENGTH_MSG, 47 }; 48 f.write_str(s) 49 } 50 } 51 52 impl From for Error { 53 #[inline] 54 fn from(_: InvalidEncodingError) -> Error { 55 Error::InvalidEncoding 56 } 57 } 58 59 impl From for Error { 60 #[inline] 61 fn from(_: InvalidLengthError) -> Error { 62 Error::InvalidLength 63 } 64 } 65 66 impl From for Error { 67 #[inline] 68 fn from(_: core::str::Utf8Error) -> Error { 69 Error::InvalidEncoding 70 } 71 } 72 73 #[cfg(feature = "std")] 74 impl From for std::io::Error { 75 fn from(err: Error) -> std::io::Error { 76 // TODO(tarcieri): better customize `ErrorKind`? 77 std::io::Error::new(std::io::ErrorKind::InvalidData, err) 78 } 79 } 80 81 impl core::error::Error for Error {}