aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/stringlist.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/stringlist.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/stringlist.rs')
-rw-r--r--src/primitive/stringlist.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/primitive/stringlist.rs b/src/primitive/stringlist.rs
index 434f2f2..872f5be 100644
--- a/src/primitive/stringlist.rs
+++ b/src/primitive/stringlist.rs
@@ -3,11 +3,9 @@ extern crate byteorder;
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
use log::trace;
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, error::ProtocolError, serialize::*};
/// StringList are represented as a Vec of Strings
///
@@ -15,7 +13,7 @@ use crate::{deserialize::*, serialize::*};
pub type StringList = Vec<String>;
impl Serialize for StringList {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let len: i32 = self.len().try_into()?;
let mut res: Vec<u8> = Vec::new();
@@ -29,7 +27,7 @@ impl Serialize for StringList {
}
impl Deserialize for StringList {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::StringList", "Parsing with length: {:?}, from bytes: {:x?}", len, &b[0..4]);
let mut res: StringList = StringList::new();
@@ -54,8 +52,8 @@ pub fn string_list_serialize() {
assert_eq!(
test_list.serialize().unwrap(),
[
- 0, 0, 0, 1, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114,
- 0, 101, 0, 100
+ 0, 0, 0, 1, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101,
+ 0, 100
]
)
}
@@ -63,8 +61,8 @@ pub fn string_list_serialize() {
#[test]
pub fn string_list_deserialize() {
let test_bytes: &[u8] = &[
- 0, 0, 0, 1, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0,
- 101, 0, 100, 0, 0, 0, 1,
+ 0, 0, 0, 1, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0,
+ 100, 0, 0, 0, 1,
];
let mut test_list = StringList::new();
test_list.push("Configured".to_string());