use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StringifiedEpochTimeUnitSeconds {
StringValue(String),
EpochTimeUnitSecondsValue(u64),
}
impl std::fmt::Display for StringifiedEpochTimeUnitSeconds {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
StringifiedEpochTimeUnitSeconds::StringValue(s) => write!(f, "{}", s),
StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => write!(f, "{}", n),
}
}
}
impl StringifiedEpochTimeUnitSeconds {
pub fn as_str(&self) -> String {
match self {
StringifiedEpochTimeUnitSeconds::StringValue(s) => s.clone(),
StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => n.to_string(),
}
}
pub fn as_num(&self) -> Option<u64> {
match self {
StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => Some(*n),
_ => None,
}
}
}
impl From<u64> for StringifiedEpochTimeUnitSeconds {
fn from(n: u64) -> Self {
StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n)
}
}
impl From<&str> for StringifiedEpochTimeUnitSeconds {
fn from(s: &str) -> Self {
StringifiedEpochTimeUnitSeconds::StringValue(s.to_string())
}
}
impl From<String> for StringifiedEpochTimeUnitSeconds {
fn from(s: String) -> Self {
StringifiedEpochTimeUnitSeconds::StringValue(s)
}
}