From a3e14b3d7380cfe1d0c6a1649def7fce2dd156e7 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 20 Dec 2023 14:03:08 +0100 Subject: fix ignorelistmanager enum conversions --- .../signalproxy/objects/ignorelistmanager.rs | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/message/signalproxy/objects/ignorelistmanager.rs b/src/message/signalproxy/objects/ignorelistmanager.rs index 7050bdd..ce4ad43 100644 --- a/src/message/signalproxy/objects/ignorelistmanager.rs +++ b/src/message/signalproxy/objects/ignorelistmanager.rs @@ -4,6 +4,7 @@ use crate::{ }; use libquassel_derive::{sync, NetworkList, NetworkMap}; +use num_derive::{FromPrimitive, ToPrimitive}; #[derive(Default, Debug, Clone, PartialEq, NetworkList, NetworkMap)] pub struct IgnoreListManager { @@ -201,8 +202,10 @@ pub struct IgnoreListItem { ////////////////////////////////////// +use num_traits::{FromPrimitive, ToPrimitive}; + #[repr(i32)] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive)] pub enum IgnoreType { SenderIgnore = 0x00, MessageIgnore = 0x01, @@ -211,19 +214,19 @@ pub enum IgnoreType { impl From for Variant { fn from(value: IgnoreType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From for IgnoreType { fn from(value: Variant) -> Self { - IgnoreType::try_from(value).unwrap() + IgnoreType::from_i32(value.try_into().unwrap()).unwrap() } } impl From for i32 { fn from(value: IgnoreType) -> Self { - value as i32 + value.to_i32().unwrap() } } @@ -241,7 +244,7 @@ impl TryFrom for IgnoreType { } #[repr(i32)] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive)] pub enum StrictnessType { UnmatchedStrictness = 0x00, SoftStrictness = 0x01, @@ -250,19 +253,19 @@ pub enum StrictnessType { impl From for Variant { fn from(value: StrictnessType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From for StrictnessType { fn from(value: Variant) -> Self { - StrictnessType::try_from(value).unwrap() + StrictnessType::from_i32(value.try_into().unwrap()).unwrap() } } impl From for i32 { fn from(value: StrictnessType) -> Self { - value as i32 + value.to_i32().unwrap() } } @@ -280,7 +283,7 @@ impl TryFrom for StrictnessType { } #[repr(i32)] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive)] pub enum ScopeType { GlobalScope = 0x00, NetworkScope = 0x01, @@ -289,19 +292,19 @@ pub enum ScopeType { impl From for Variant { fn from(value: ScopeType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From for ScopeType { fn from(value: Variant) -> Self { - ScopeType::try_from(value).unwrap() + ScopeType::from_i32(value.try_into().unwrap()).unwrap() } } impl From for i32 { fn from(value: ScopeType) -> Self { - value as i32 + value.to_i32().unwrap() } } -- cgit v1.2.3