mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
fix handling empty data
This commit is contained in:
parent
d24f83727c
commit
dd4b6260a1
1 changed files with 22 additions and 3 deletions
|
|
@ -247,17 +247,36 @@ pub struct FullLogLine {
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
pub version: TinyAsciiStr<16>,
|
pub version: TinyAsciiStr<16>,
|
||||||
pub exception: Option<FullException>,
|
pub exception: Option<FullException>,
|
||||||
#[serde(default)]
|
#[serde(default, deserialize_with = "deserialize_data")]
|
||||||
pub data: HashMap<String, String>,
|
pub data: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_data<'de, D: Deserializer<'de>>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> Result<HashMap<String, String>, D::Error> {
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum Data {
|
||||||
|
Data(HashMap<String, String>),
|
||||||
|
#[allow(dead_code)]
|
||||||
|
Empty(Vec<()>),
|
||||||
|
}
|
||||||
|
let data = Data::deserialize(deserializer)?;
|
||||||
|
Ok(match data {
|
||||||
|
Data::Data(data) => data,
|
||||||
|
Data::Empty(_) => HashMap::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
impl FullLogLine {
|
impl FullLogLine {
|
||||||
pub fn has_data(&self) -> bool {
|
pub fn has_data(&self) -> bool {
|
||||||
self.data.keys().any(|key| key.as_str() != "app")
|
self.data.keys().any(|key| key.as_str() != "app")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data(&self) -> impl Iterator<Item = (&str, &str)> {
|
pub fn data(&self) -> impl Iterator<Item = (&str, &str)> {
|
||||||
self.data.iter().map(|(key, value)| (key.as_str(), value.as_str()))
|
self.data
|
||||||
|
.iter()
|
||||||
|
.map(|(key, value)| (key.as_str(), value.as_str()))
|
||||||
.filter(|(key, _)| *key != "app")
|
.filter(|(key, _)| *key != "app")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue