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