diff --git a/src/formats/serde.rs b/src/formats/serde.rs index a7fd1e5..c2741c2 100644 --- a/src/formats/serde.rs +++ b/src/formats/serde.rs @@ -4,6 +4,8 @@ use std::collections::HashMap; use zvariant::OwnedValue; /// Serialize actions +/// # Errors +/// Will return an empty map if there are no actions pub fn serialize_actions(actions: &[String], serializer: S) -> Result where S: Serializer, @@ -21,6 +23,8 @@ where } /// Serialize hints +/// # Errors +/// Will return an empty map if there are no hints pub fn serialize_hints( hints: &HashMap, serializer: S, @@ -45,35 +49,34 @@ impl Serialize for HintValueSerializer<'_> { where S: Serializer, { - let signature = self.0.value_signature().to_string(); // Signature + let signature = self.0.value_signature().to_string(); // Get signature // Extract the raw value correctly - let raw_value = if let Ok(v) = self.0.downcast_ref::() { // BYTE: y - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // BOOLEAN: b - Value::Bool(v) - } else if let Ok(v) = self.0.downcast_ref::() { // INT16: n - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // UINT16: q - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // INT32: i - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // UINT32: u - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // INT64: x - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // UINT64: t - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // DOUBLE: d - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { // STRING: s - Value::String(v.clone()) - } else if let Ok(v) = self.0.downcast_ref::<&str>() { // str - Value::String(v.to_string()) - } else { // Unsupported types - Value::Null // Fallback to Null - // Not implemented: UNIX_FD: h, OBJECT_PATH: o, SIGNATURE: g - }; + let raw_value = if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // BYTE: y + } else if let Ok(v) = self.0.downcast_ref::() { + Value::Bool(v) // BOOLEAN: b + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // INT16: n + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // UINT16: q + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // INT32: i + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // UINT32: u + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // INT64: x + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // UINT64: t + } else if let Ok(v) = self.0.downcast_ref::() { + Value::from(v) // DOUBLE: d + } else if let Ok(v) = self.0.downcast_ref::() { + Value::String(v.clone()) // STRING: s + } else if let Ok(v) = self.0.downcast_ref::<&str>() { + Value::String(v.to_string()) // str + } else { + Value::Null // Unsupported types: fallback to Null + }; // Not implemented: UNIX_FD: h, OBJECT_PATH: o, SIGNATURE: g // Serialize the final structure as a map let mut map = serializer.serialize_map(Some(2))?; @@ -81,4 +84,4 @@ impl Serialize for HintValueSerializer<'_> { map.serialize_entry("value", &raw_value)?; map.end() } -} \ No newline at end of file +}