1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use anyhow::Result; use crate::frame::types; #[derive(Debug)] pub struct Error { pub code: i32, pub reason: String, } impl Error { pub fn deserialize(buf: &mut &[u8]) -> Result<Self> { let code = types::read_int(buf)?; let reason = types::read_string(buf)?.to_owned(); Ok(Error { code, reason }) } } impl Into<anyhow::Error> for Error { fn into(self) -> anyhow::Error { anyhow!("Error (code {}): {}", self.code, self.reason) } }