aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/signedint.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-02-22 22:59:01 +0100
committerMax Audron <audron@cocaine.farm>2025-02-22 22:59:01 +0100
commitb8ad94cd5061445a45d0790eee36014d34ad6817 (patch)
treefb7d11e136b968d2f2b3593ba9163894baed8912 /src/primitive/signedint.rs
parentupdate dependencies and fix errors (diff)
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.
Diffstat (limited to 'src/primitive/signedint.rs')
-rw-r--r--src/primitive/signedint.rs20
1 files changed, 9 insertions, 11 deletions
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<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, 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::<BigEndian>()?));
}
}
impl Serialize for i32 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, 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::<BigEndian>()?));
}
}
impl Serialize for i16 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, 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::<BigEndian>()?));
}
}
impl Serialize for i8 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, 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()?));
}