diff options
| author | Max Audron <audron@cocaine.farm> | 2023-12-20 14:03:08 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2023-12-20 14:03:08 +0100 |
| commit | a3e14b3d7380cfe1d0c6a1649def7fce2dd156e7 (patch) | |
| tree | 296dcf0881f64cebb65f90f1c4b94c33681dac06 /src | |
| parent | rework Network derives to be more consistent (diff) | |
fix ignorelistmanager enum conversions
Diffstat (limited to '')
| -rw-r--r-- | src/message/signalproxy/objects/ignorelistmanager.rs | 27 |
1 files changed, 15 insertions, 12 deletions
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<IgnoreType> for Variant { fn from(value: IgnoreType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From<Variant> for IgnoreType { fn from(value: Variant) -> Self { - IgnoreType::try_from(value).unwrap() + IgnoreType::from_i32(value.try_into().unwrap()).unwrap() } } impl From<IgnoreType> for i32 { fn from(value: IgnoreType) -> Self { - value as i32 + value.to_i32().unwrap() } } @@ -241,7 +244,7 @@ impl TryFrom<i32> 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<StrictnessType> for Variant { fn from(value: StrictnessType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From<Variant> for StrictnessType { fn from(value: Variant) -> Self { - StrictnessType::try_from(value).unwrap() + StrictnessType::from_i32(value.try_into().unwrap()).unwrap() } } impl From<StrictnessType> for i32 { fn from(value: StrictnessType) -> Self { - value as i32 + value.to_i32().unwrap() } } @@ -280,7 +283,7 @@ impl TryFrom<i32> 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<ScopeType> for Variant { fn from(value: ScopeType) -> Self { - Variant::i32(value as i32) + Variant::i32(value.to_i32().unwrap()) } } impl From<Variant> for ScopeType { fn from(value: Variant) -> Self { - ScopeType::try_from(value).unwrap() + ScopeType::from_i32(value.try_into().unwrap()).unwrap() } } impl From<ScopeType> for i32 { fn from(value: ScopeType) -> Self { - value as i32 + value.to_i32().unwrap() } } |
