From b8ad94cd5061445a45d0790eee36014d34ad6817 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sat, 22 Feb 2025 22:59:01 +0100 Subject: replace deprecated failure crate with thiserror this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense. --- src/primitive/signedint.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/primitive/signedint.rs') diff --git a/src/primitive/signedint.rs b/src/primitive/signedint.rs index 2d2029d..b139685 100644 --- a/src/primitive/signedint.rs +++ b/src/primitive/signedint.rs @@ -4,57 +4,55 @@ use std::io::Cursor; use std::result::Result; use std::vec::Vec; -use failure::Error; - -use crate::{deserialize::*, serialize::*}; +use crate::{deserialize::*, error::ProtocolError, serialize::*}; impl Serialize for i64 { - fn serialize(&self) -> Result, Error> { + fn serialize(&self) -> Result, ProtocolError> { Ok(Vec::from(self.to_be_bytes())) } } impl Deserialize for i64 { - fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { let mut rdr = Cursor::new(&b[0..8]); return Ok((8, rdr.read_i64::()?)); } } impl Serialize for i32 { - fn serialize(&self) -> Result, Error> { + fn serialize(&self) -> Result, ProtocolError> { Ok(Vec::from(self.to_be_bytes())) } } impl Deserialize for i32 { - fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { let mut rdr = Cursor::new(&b[0..4]); return Ok((4, rdr.read_i32::()?)); } } impl Serialize for i16 { - fn serialize(&self) -> Result, Error> { + fn serialize(&self) -> Result, ProtocolError> { Ok(Vec::from(self.to_be_bytes())) } } impl Deserialize for i16 { - fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { let mut rdr = Cursor::new(&b[0..2]); return Ok((2, rdr.read_i16::()?)); } } impl Serialize for i8 { - fn serialize(&self) -> Result, Error> { + fn serialize(&self) -> Result, ProtocolError> { Ok(Vec::from(self.to_be_bytes())) } } impl Deserialize for i8 { - fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { let mut rdr = Cursor::new(&b[0..1]); return Ok((1, rdr.read_i8()?)); } -- cgit v1.2.3