starting to fix hints serialization

This commit is contained in:
Candifloss 2024-09-27 16:28:22 +05:30
parent f568ac111d
commit 45bf3a87b9
2 changed files with 27 additions and 5 deletions

View File

@ -1,8 +1,8 @@
use serde::{Serialize, Serializer};
/*
use std::collections::HashMap;
use std::hash::BuildHasher;
use zvariant::OwnedValue; */
use zvariant::OwnedValue;
//use std::hash::BuildHasher;
use serde::ser::SerializeMap;
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
where
@ -20,6 +20,27 @@ where
map.serialize(serializer)
}
/*
pub fn serialize_hints<S>(hints: &HashMap<String, OwnedValue>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut map = serializer.serialize_map(Some(hints.len()))?;
for (key, value) in hints {
// Try to cast the value to a string, otherwise fallback to debug format
let value_str = match value.downcast_ref::<String>() {
Ok(s) => s.clone(), // Successfully cast to String
Err(_) => format!("{:?}", value), // Fallback for non-String values
};
map.serialize_entry(key, &value_str)?;
}
map.end()
}
*/
/*
pub fn serialize_hints<S, H>(
hints: &HashMap<String, OwnedValue, H>,
@ -38,4 +59,5 @@ where
map.serialize(serializer)
}
*/

View File

@ -1,4 +1,4 @@
use crate::formats::serde::serialize_actions;
use crate::formats::serde::serialize_actions;//,serialize_hints};
use serde::Serialize;
use std::collections::HashMap;
use zbus::{message::Body, Result};