diff options
| author | Max Audron <audron@cocaine.farm> | 2023-12-20 13:13:00 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2023-12-20 13:13:00 +0100 |
| commit | e6980211c4c53fc1eeb686cd12363a8fa603daa3 (patch) | |
| tree | 2c248fc32d258dea722dbbefd7ab5465954e2ebc /src/primitive/variant.rs | |
| parent | use VariantMap as target for generic NetworkMap for HashMap impl (diff) | |
rework Network derives to be more consistent
i don't even know anymore, blame past me
Diffstat (limited to '')
| -rw-r--r-- | src/primitive/variant.rs | 32 |
1 files changed, 3 insertions, 29 deletions
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<T> -impl<T> crate::message::Network for Vec<T> -where - T: std::convert::TryFrom<Variant> + Into<Variant> + 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<T> -impl<T, S> crate::message::Network for HashMap<T, S> +impl<T, S> crate::message::NetworkList for HashMap<T, S> where T: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq, S: std::convert::TryFrom<Variant> + Into<Variant> + 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)| { |
