diff --git a/src/formats/rson.rs b/src/formats/rson.rs index 8f03db6..9576477 100644 --- a/src/formats/rson.rs +++ b/src/formats/rson.rs @@ -5,7 +5,6 @@ use rson_rs::ser::to_string as rson_string; impl Notification { pub fn rson(&self) -> Result { - rson_string(self) - .map_err(|e| RsonError::Message(format!("RSON serialization error: {}", e))) + rson_string(self).map_err(|e| RsonError::Message(format!("RSON serialization error: {e}"))) } } diff --git a/src/formats/serde.rs b/src/formats/serde.rs index 2666461..3e1fa97 100644 --- a/src/formats/serde.rs +++ b/src/formats/serde.rs @@ -1,8 +1,7 @@ -use serde::ser::{Serialize, Serializer, SerializeMap}; +use serde::ser::{Serialize, SerializeMap, Serializer}; +use serde_json::{Map, Value}; use std::collections::HashMap; -use std::convert::TryInto; // Import TryInto -use serde_json::{Map, Value as JsonValue}; // Alias serde_json::Value to JsonValue -use zvariant::{OwnedValue, Value as ZValue}; // Alias zvariant::Value to ZValue +use zvariant::OwnedValue; pub fn serialize_actions(actions: &[String], serializer: S) -> Result where @@ -13,7 +12,7 @@ where // Actions are in pairs: [id, label, id, label, ...] for pair in actions.chunks(2) { if let [id, label] = pair { - map.insert(id.clone(), JsonValue::String(label.clone())); + map.insert(id.clone(), Value::String(label.clone())); } } @@ -36,50 +35,32 @@ where map.end() } -/* -impl<'a> Serialize for HintValueSerializer<'a> { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - // Access the signature and value parts of the OwnedValue - let signature = self.0.value_signature().to_string(); - let value = &self.0; - - // Serialize them as a map with "signature" and "value" fields - let mut map = serializer.serialize_map(Some(2))?; - map.serialize_entry("signature", &signature)?; - map.serialize_entry("value", value)?; - map.end() - } -}*/ - // A custom struct to handle serialization of OwnedValue struct HintValueSerializer<'a>(&'a OwnedValue); - -impl<'a> Serialize for HintValueSerializer<'a> { +impl Serialize for HintValueSerializer<'_> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { + // Signature let signature = self.0.value_signature().to_string(); // Extract the raw value correctly let raw_value = if let Ok(v) = self.0.downcast_ref::() { - JsonValue::from(v) // Removed *v + Value::from(v) } else if let Ok(v) = self.0.downcast_ref::() { - JsonValue::from(v) // Removed *v + Value::from(v) } else if let Ok(v) = self.0.downcast_ref::() { - JsonValue::from(v) // Removed *v + Value::from(v) } else if let Ok(v) = self.0.downcast_ref::() { - JsonValue::Bool(v) // Removed *v + Value::Bool(v) } else if let Ok(v) = self.0.downcast_ref::() { - JsonValue::String(v.clone()) + Value::String(v.clone()) } else if let Ok(v) = self.0.downcast_ref::<&str>() { - JsonValue::String(v.to_string()) + Value::String(v.to_string()) } else { - JsonValue::Null // Unsupported types fallback to Null + Value::Null // Unsupported types fallback to Null }; // Serialize the final structure as a map diff --git a/src/main.rs b/src/main.rs index 54814c9..b0f57d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,8 +134,8 @@ async fn main() -> Result<()> { "r" => { // Print the rson version match notif.rson() { - Ok(rson_string) => println!("{}", rson_string), - Err(e) => eprintln!("Failed to convert to RSON: {}", e), + Ok(rson_string) => println!("{rson_string}"), + Err(e) => eprintln!("Failed to convert to RSON: {e}"), } } "p" => {