aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/variant.rs
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/variant.rs
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/variant.rs')
-rw-r--r--src/primitive/variant.rs20
1 files changed, 6 insertions, 14 deletions
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)
}
}
}