use serde::{ser::Serializer, Serialize}; use smart_default::SmartDefault; use std::fmt::Debug; use std::sync::Arc; #[cfg(feature = "check_latency")] use std::time::Instant; #[allow(unused)] #[derive(Copy, Clone, Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum Alignment { Left, Center, Right, } impl Default for Alignment { fn default() -> Self { Self::Center } } #[allow(unused)] #[derive(Copy, Clone, Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum Markup { None, Pango, } impl Default for Markup { fn default() -> Self { Self::None } } fn arc_default(arc: &Arc, serializer: S) -> Result where S: Serializer, { serializer.serialize_str(arc) } #[cfg(feature = "check_latency")] fn time_diff(&instant: &Instant, serializer: S) -> Result where S: Serializer, { let duration = Instant::now() - instant; //let duration = duration.as_secs_f32(); serializer.serialize_str(&format!("{:?}", duration)) } #[derive(Clone, Serialize, Debug, SmartDefault)] pub struct Block { pub full_text: Box, #[serde(skip_serializing_if = "Option::is_none")] pub short_text: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub color: Option>, #[serde(skip_serializing_if = "Option::is_none", rename = "background")] pub background_color: Option>, #[serde(skip_serializing_if = "Option::is_none", rename = "border")] pub border_color: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub border_top: Option, #[serde(skip_serializing_if = "Option::is_none")] pub border_right: Option, #[serde(skip_serializing_if = "Option::is_none")] pub border_bottom: Option, #[serde(skip_serializing_if = "Option::is_none")] pub border_left: Option, #[serde(skip_serializing_if = "Option::is_none")] pub min_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub align: Option, pub name: Box, #[serde(serialize_with = "arc_default")] #[default = ""] pub instance: Arc, #[serde(skip_serializing_if = "Option::is_none")] pub urgent: Option, #[serde(skip_serializing_if = "Option::is_none")] pub separator: Option, #[serde(skip_serializing_if = "Option::is_none")] pub separator_block_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub markup: Option, #[serde(serialize_with = "time_diff")] #[default(Instant::now())] #[cfg(feature = "check_latency")] pub latency: Instant, } #[derive(Clone, Debug)] pub struct TileData { pub sender_id: usize, pub block: Block, }