From e6980211c4c53fc1eeb686cd12363a8fa603daa3 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 20 Dec 2023 13:13:00 +0100 Subject: rework Network derives to be more consistent i don't even know anymore, blame past me --- src/primitive/variant.rs | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'src/primitive/variant.rs') diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs index 673d39f..b306ea7 100644 --- a/src/primitive/variant.rs +++ b/src/primitive/variant.rs @@ -86,38 +86,12 @@ impl From<&str> for Variant { /// Implements the Network trait genericly for everything that /// can be a VariantList / Vec -impl crate::message::Network for Vec -where - T: std::convert::TryFrom + Into + Clone, -{ - type Item = super::VariantList; - - fn to_network(&self) -> Self::Item { - self.iter().map(|i| (*i).clone().into()).collect() - } - - fn from_network(input: &mut Self::Item) -> Self { - input - .iter() - .map(|i| match T::try_from(i.clone()) { - Ok(it) => it, - // TODO handle error - _ => unreachable!(), - }) - .collect() - } -} - -/// Implements the Network trait genericly for everything that -/// can be a VariantList / Vec -impl crate::message::Network for HashMap +impl crate::message::NetworkList for HashMap where T: std::convert::TryFrom + Into + Clone + std::hash::Hash + std::cmp::Eq, S: std::convert::TryFrom + Into + Clone + std::hash::Hash + std::cmp::Eq, { - type Item = super::VariantList; - - fn to_network(&self) -> Self::Item { + fn to_network_list(&self) -> VariantList { let mut res = Vec::with_capacity(self.len() * 2); self.iter().for_each(|(k, v)| { @@ -128,7 +102,7 @@ where return res; } - fn from_network(input: &mut Self::Item) -> Self { + fn from_network_list(input: &mut VariantList) -> Self { let mut res = HashMap::with_capacity(input.len() / 2); input.iter().tuples().for_each(|(k, v)| { -- cgit v1.2.3