clippy and comments
This commit is contained in:
parent
ac2dc744d5
commit
8e2d189a4d
@ -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<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
||||
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<S>(
|
||||
hints: &HashMap<String, OwnedValue>,
|
||||
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::<u8>() { // BYTE: y
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<bool>() { // BOOLEAN: b
|
||||
Value::Bool(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i16>() { // INT16: n
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u16>() { // UINT16: q
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() { // INT32: i
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u32>() { // UINT32: u
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i64>() { // INT64: x
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u64>() { // UINT64: t
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<f64>() { // DOUBLE: d
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<String>() { // 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::<u8>() {
|
||||
Value::from(v) // BYTE: y
|
||||
} else if let Ok(v) = self.0.downcast_ref::<bool>() {
|
||||
Value::Bool(v) // BOOLEAN: b
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i16>() {
|
||||
Value::from(v) // INT16: n
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u16>() {
|
||||
Value::from(v) // UINT16: q
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() {
|
||||
Value::from(v) // INT32: i
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u32>() {
|
||||
Value::from(v) // UINT32: u
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i64>() {
|
||||
Value::from(v) // INT64: x
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u64>() {
|
||||
Value::from(v) // UINT64: t
|
||||
} else if let Ok(v) = self.0.downcast_ref::<f64>() {
|
||||
Value::from(v) // DOUBLE: d
|
||||
} else if let Ok(v) = self.0.downcast_ref::<String>() {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user