use serde::{Deserialize, Deserializer}; use serde_derive::Deserialize; use serde_json::Value; use std::{collections::HashMap, ops::Deref}; #[derive(Clone, Debug, Deserialize)] pub struct Event { pub title: String, pub message: String, pub context: HashMap, pub contexts: HashMap, #[serde(deserialize_with = "tags")] pub tags: HashMap, #[serde(deserialize_with = "entries")] pub entries: HashMap>, pub user: Option, pub release: Option, pub dist: Option, #[serde(default)] pub attachments: HashMap, } #[derive(Clone, Debug, Deserialize, PartialEq)] pub struct Contexts { pub r#type: String, #[serde(flatten)] pub data: HashMap, } impl Deref for Contexts { type Target = HashMap; fn deref(&self) -> &Self::Target { &self.data } } #[derive(Deserialize)] struct Tag { pub key: String, pub value: String, } fn tags<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let mut map = HashMap::new(); for tag in Vec::::deserialize(deserializer)? { map.insert(tag.key, tag.value); } Ok(map) } #[derive(Deserialize)] struct Entry { pub r#type: String, pub data: HashMap, } fn entries<'de, D>(deserializer: D) -> Result>, D::Error> where D: Deserializer<'de>, { let mut map = HashMap::new(); for tag in Vec::::deserialize(deserializer)? { map.insert(tag.r#type, tag.data); } Ok(map) } #[derive(Clone, Debug, Deserialize, PartialEq)] pub struct User { pub data: Option>, pub email: Option, pub id: Option, pub ip_address: Option, pub name: Option, pub username: Option, } #[derive(Clone, Debug, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] pub struct Release { pub short_version: Option, pub version: Option, pub version_info: Option, } #[derive(Clone, Debug, Deserialize, PartialEq)] pub struct VersionInfo { pub description: String, pub version: HashMap, } #[derive(Clone, Debug, Deserialize, PartialEq)] pub struct Attachment { pub id: String, pub name: String, pub sha1: String, pub size: usize, } #[derive(Clone, Debug, Deserialize)] #[allow(clippy::module_name_repetitions)] pub struct MinEvent { #[serde(rename = "eventID")] pub event_id: String, pub user: Option, }