aboutsummaryrefslogtreecommitdiff
path: root/src/primitive
diff options
context:
space:
mode:
authorMax Audron <me@audron.dev>2026-02-21 13:32:00 +0100
committerMax Audron <me@audron.dev>2026-02-21 13:32:00 +0100
commit8882c121f83cf4513eaee7515d6dcea133a65d69 (patch)
treee2818c5d99f209159fd904e0c75d4bc30c262e82 /src/primitive
parentremove old readme.org (diff)
replace all match_variant instances with try_into
the match_variant macro was unclear, unreadable and no longer needed as we have automaticly derived from implementations for all Variant enum fields now
Diffstat (limited to 'src/primitive')
-rw-r--r--src/primitive/bufferid.rs2
-rw-r--r--src/primitive/signedint.rs8
-rw-r--r--src/primitive/variant.rs20
3 files changed, 11 insertions, 19 deletions
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs
index 59e1ace..334e976 100644
--- a/src/primitive/bufferid.rs
+++ b/src/primitive/bufferid.rs
@@ -53,7 +53,7 @@ impl NetworkList for Vec<BufferId> {
}
fn from_network_list(input: &mut super::VariantList) -> Self {
- input.iter().map(|b| match_variant!(b, Variant::BufferId)).collect()
+ input.iter().map(|b| b.try_into().unwrap()).collect()
}
}
diff --git a/src/primitive/signedint.rs b/src/primitive/signedint.rs
index 6bf009f..8591c03 100644
--- a/src/primitive/signedint.rs
+++ b/src/primitive/signedint.rs
@@ -17,7 +17,7 @@ impl Serialize for i64 {
impl Deserialize for i64 {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..8]);
- return Ok((8, rdr.read_i64::<BigEndian>()?));
+ Ok((8, rdr.read_i64::<BigEndian>()?))
}
}
@@ -34,7 +34,7 @@ impl Serialize for i32 {
impl Deserialize for i32 {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..4]);
- return Ok((4, rdr.read_i32::<BigEndian>()?));
+ Ok((4, rdr.read_i32::<BigEndian>()?))
}
}
@@ -51,7 +51,7 @@ impl Serialize for i16 {
impl Deserialize for i16 {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..2]);
- return Ok((2, rdr.read_i16::<BigEndian>()?));
+ Ok((2, rdr.read_i16::<BigEndian>()?))
}
}
@@ -68,7 +68,7 @@ impl Serialize for i8 {
impl Deserialize for i8 {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..1]);
- return Ok((1, rdr.read_i8()?));
+ Ok((1, rdr.read_i8()?))
}
}
diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs
index 8a1c777..61e6752 100644
--- a/src/primitive/variant.rs
+++ b/src/primitive/variant.rs
@@ -61,22 +61,14 @@ pub enum Variant {
i8(i8),
}
-impl From<Variant> for String {
- fn from(input: Variant) -> Self {
- match input {
- Variant::String(value) => value,
- Variant::ByteArray(value) => value,
- _ => panic!("unknown variant expected string or bytearray {:?}", input),
- }
- }
-}
+impl TryFrom<Variant> for String {
+ type Error = ProtocolError;
-impl From<&Variant> for String {
- fn from(input: &Variant) -> Self {
+ fn try_from(input: Variant) -> Result<Self, Self::Error> {
match input {
- Variant::String(value) => value.clone(),
- Variant::ByteArray(value) => value.clone(),
- _ => panic!("unknown variant expected string or bytearray {:?}", input),
+ Variant::String(value) => Ok(value),
+ Variant::ByteArray(value) => Ok(value),
+ _ => Err(ProtocolError::UnknownVariant)
}
}
}