clippy and comments
This commit is contained in:
parent
afe7f6c908
commit
829a8741ee
@ -5,7 +5,6 @@ use rson_rs::ser::to_string as rson_string;
|
|||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
pub fn rson(&self) -> Result<String, RsonError> {
|
pub fn rson(&self) -> Result<String, RsonError> {
|
||||||
rson_string(self)
|
rson_string(self).map_err(|e| RsonError::Message(format!("RSON serialization error: {e}")))
|
||||||
.map_err(|e| RsonError::Message(format!("RSON serialization error: {}", e)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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::collections::HashMap;
|
||||||
use std::convert::TryInto; // Import TryInto
|
use zvariant::OwnedValue;
|
||||||
use serde_json::{Map, Value as JsonValue}; // Alias serde_json::Value to JsonValue
|
|
||||||
use zvariant::{OwnedValue, Value as ZValue}; // Alias zvariant::Value to ZValue
|
|
||||||
|
|
||||||
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@ -13,7 +12,7 @@ where
|
|||||||
// Actions are in pairs: [id, label, id, label, ...]
|
// Actions are in pairs: [id, label, id, label, ...]
|
||||||
for pair in actions.chunks(2) {
|
for pair in actions.chunks(2) {
|
||||||
if let [id, label] = pair {
|
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()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
impl<'a> Serialize for HintValueSerializer<'a> {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
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
|
// A custom struct to handle serialization of OwnedValue
|
||||||
struct HintValueSerializer<'a>(&'a OwnedValue);
|
struct HintValueSerializer<'a>(&'a OwnedValue);
|
||||||
|
|
||||||
|
impl Serialize for HintValueSerializer<'_> {
|
||||||
impl<'a> Serialize for HintValueSerializer<'a> {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
|
// Signature
|
||||||
let signature = self.0.value_signature().to_string();
|
let signature = self.0.value_signature().to_string();
|
||||||
|
|
||||||
// Extract the raw value correctly
|
// Extract the raw value correctly
|
||||||
let raw_value = if let Ok(v) = self.0.downcast_ref::<u8>() {
|
let raw_value = if let Ok(v) = self.0.downcast_ref::<u8>() {
|
||||||
JsonValue::from(v) // Removed *v
|
Value::from(v)
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() {
|
} else if let Ok(v) = self.0.downcast_ref::<i32>() {
|
||||||
JsonValue::from(v) // Removed *v
|
Value::from(v)
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<u64>() {
|
} else if let Ok(v) = self.0.downcast_ref::<u64>() {
|
||||||
JsonValue::from(v) // Removed *v
|
Value::from(v)
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<bool>() {
|
} else if let Ok(v) = self.0.downcast_ref::<bool>() {
|
||||||
JsonValue::Bool(v) // Removed *v
|
Value::Bool(v)
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<String>() {
|
} else if let Ok(v) = self.0.downcast_ref::<String>() {
|
||||||
JsonValue::String(v.clone())
|
Value::String(v.clone())
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<&str>() {
|
} else if let Ok(v) = self.0.downcast_ref::<&str>() {
|
||||||
JsonValue::String(v.to_string())
|
Value::String(v.to_string())
|
||||||
} else {
|
} else {
|
||||||
JsonValue::Null // Unsupported types fallback to Null
|
Value::Null // Unsupported types fallback to Null
|
||||||
};
|
};
|
||||||
|
|
||||||
// Serialize the final structure as a map
|
// Serialize the final structure as a map
|
||||||
|
@ -134,8 +134,8 @@ async fn main() -> Result<()> {
|
|||||||
"r" => {
|
"r" => {
|
||||||
// Print the rson version
|
// Print the rson version
|
||||||
match notif.rson() {
|
match notif.rson() {
|
||||||
Ok(rson_string) => println!("{}", rson_string),
|
Ok(rson_string) => println!("{rson_string}"),
|
||||||
Err(e) => eprintln!("Failed to convert to RSON: {}", e),
|
Err(e) => eprintln!("Failed to convert to RSON: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"p" => {
|
"p" => {
|
||||||
|
Loading…
Reference in New Issue
Block a user