From cc542048e369dda0a773e1e3a4601dc7d20ff16a Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sat, 21 Feb 2026 17:48:06 +0100 Subject: Syncable trait error handling --- .../signalproxy/objects/ignorelistmanager.rs | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'src/message/signalproxy/objects/ignorelistmanager.rs') diff --git a/src/message/signalproxy/objects/ignorelistmanager.rs b/src/message/signalproxy/objects/ignorelistmanager.rs index b97ca77..4697611 100644 --- a/src/message/signalproxy/objects/ignorelistmanager.rs +++ b/src/message/signalproxy/objects/ignorelistmanager.rs @@ -1,4 +1,5 @@ use crate::{ + error::ProtocolError, message::{Class, Syncable}, primitive::Variant, }; @@ -118,7 +119,7 @@ impl IgnoreListManager { #[cfg(feature = "client")] impl crate::message::StatefulSyncableClient for IgnoreListManager { - fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError> where Self: Sized, { @@ -142,12 +143,13 @@ impl crate::message::StatefulSyncableClient for IgnoreListManager { } _ => (), } + Ok(()) } } #[cfg(feature = "server")] impl crate::message::StatefulSyncableServer for IgnoreListManager { - fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError> where Self: Sized, { @@ -171,6 +173,7 @@ impl crate::message::StatefulSyncableServer for IgnoreListManager { } _ => (), } + Ok(()) } } @@ -201,8 +204,6 @@ pub struct IgnoreListItem { ////////////////////////////////////// -use num_traits::{FromPrimitive, ToPrimitive}; - #[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive)] pub enum IgnoreType { @@ -213,19 +214,22 @@ pub enum IgnoreType { impl From for Variant { fn from(value: IgnoreType) -> Self { - Variant::i32(value.to_i32().unwrap()) + Variant::i32(value as i32) } } -impl From for IgnoreType { - fn from(value: Variant) -> Self { - IgnoreType::from_i32(value.try_into().unwrap()).unwrap() +impl TryFrom for IgnoreType { + type Error = ProtocolError; + + fn try_from(value: Variant) -> Result { + let i: i32 = value.try_into()?; + Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } } impl From for i32 { fn from(value: IgnoreType) -> Self { - value.to_i32().unwrap() + value as i32 } } @@ -252,19 +256,22 @@ pub enum StrictnessType { impl From for Variant { fn from(value: StrictnessType) -> Self { - Variant::i32(value.to_i32().unwrap()) + Variant::i32(value as i32) } } -impl From for StrictnessType { - fn from(value: Variant) -> Self { - StrictnessType::from_i32(value.try_into().unwrap()).unwrap() +impl TryFrom for StrictnessType { + type Error = ProtocolError; + + fn try_from(value: Variant) -> Result { + let i: i32 = value.try_into()?; + Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } } impl From for i32 { fn from(value: StrictnessType) -> Self { - value.to_i32().unwrap() + value as i32 } } @@ -291,19 +298,22 @@ pub enum ScopeType { impl From for Variant { fn from(value: ScopeType) -> Self { - Variant::i32(value.to_i32().unwrap()) + Variant::i32(value as i32) } } -impl From for ScopeType { - fn from(value: Variant) -> Self { - ScopeType::from_i32(value.try_into().unwrap()).unwrap() +impl TryFrom for ScopeType { + type Error = ProtocolError; + + fn try_from(value: Variant) -> Result { + let i: i32 = value.try_into()?; + Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } } impl From for i32 { fn from(value: ScopeType) -> Self { - value.to_i32().unwrap() + value as i32 } } -- cgit v1.2.3