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
use alloc::vec::Vec; #[derive(Debug, PartialEq, Eq)] pub enum EncodeError { UnsupportedOperation, Static(&'static [u8]), Dynamic(Vec<u8>), } impl EncodeError { pub fn message_bytes(&self) -> &[u8] { match self { EncodeError::UnsupportedOperation => &b"unsupported operation"[..], EncodeError::Static(msg) => msg, EncodeError::Dynamic(msg) => msg.as_slice(), } } } #[derive(Debug, PartialEq, Eq)] pub enum DecodeError { InputTooShort, InputTooLong, InvalidValue, UnsupportedOperation, ArrayDecodeErr, Static(&'static [u8]), Dynamic(Vec<u8>), } impl DecodeError { pub fn message_bytes(&self) -> &[u8] { match self { DecodeError::InputTooShort => &b"input too short"[..], DecodeError::InputTooLong => &b"input too long"[..], DecodeError::InvalidValue => &b"invalid value"[..], DecodeError::UnsupportedOperation => &b"unsupported operation"[..], DecodeError::ArrayDecodeErr => &b"array decode error"[..], DecodeError::Static(msg) => msg, DecodeError::Dynamic(msg) => msg.as_slice(), } } }