attempt - hint serialize

This commit is contained in:
Candifloss 2024-10-14 16:38:55 +05:30
parent 21002f6521
commit 58aed0897d
2 changed files with 20 additions and 2 deletions

View File

@ -20,6 +20,24 @@ where
map.serialize(serializer)
}
pub fn serialize_hints<S>(hints: &HashMap<String, OwnedValue>, serializer: Serializer) -> Result<S::Ok, S::Error>
{
let mut hint_map = serde_json::Map::new();
for hint in hints {
if let (hint_name, hint_val) = hint {
let mut h = serde_json::Map::new();
let sig = hint_val.value_signature();
let val = hint_val.try_clone();
h.insert(sig.to_string(), serde_json::Value::String(val));
hint_map.insert(hint_name.clone(), serde_json::Value::Object(h.clone()));
}
}
hint_map.serialize(serializer)
}
/*
pub fn serialize_hints<S>(hints: &HashMap<String, OwnedValue>, serializer: S) -> Result<S::Ok, S::Error>
where

View File

@ -1,4 +1,4 @@
use crate::formats::serde::serialize_actions; //,serialize_hints};
use crate::formats::serde::{serialize_actions,serialize_hints};
use serde::Serialize;
use std::collections::HashMap;
use zbus::{message::Body, Result};
@ -21,7 +21,7 @@ pub struct Notification {
#[serde(serialize_with = "serialize_actions")]
actions: Vec<String>,
// Useful extra data - notif type, urgency, notif sound, icon data, etc.
//#[serde(serialize_with = "serialize_hints")]
#[serde(serialize_with = "serialize_hints")]
hints: HashMap<String, OwnedValue>,
// Seconds till this notif expires. Optional
expir_timeout: i32,