diff options
Diffstat (limited to '')
| -rw-r--r-- | src/primitive/bufferid.rs | 2 | ||||
| -rw-r--r-- | src/primitive/signedint.rs | 8 | ||||
| -rw-r--r-- | src/primitive/variant.rs | 20 |
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) } } } |
