use chrono::NaiveDateTime;
use crate::domain::{Array, Node, Table};
use crate::error::ConfigerError;
pub struct NodeConverter;
impl NodeConverter {
pub fn try_datetime(rvt: Result<&Node, ConfigerError>) -> Option<&NaiveDateTime> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_string(rvt: Result<&Node, ConfigerError>) -> Option<&String> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_str(rvt: Result<&Node, ConfigerError>) -> Option<&str> {
match rvt {
Ok(Node::String(s)) => Some(s),
_ => None,
}
}
pub fn try_bool(rvt: Result<&Node, ConfigerError>) -> Option<&bool> {
match rvt {
Ok(Node::Boolean(b)) => Some(b),
_ => None,
}
}
pub fn try_nested(rvt: Result<&Node, ConfigerError>) -> Option<&Table> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_array(rvt: Result<&Node, ConfigerError>) -> Option<&Array> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_u128(rvt: Result<&Node, ConfigerError>) -> Option<&u128> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_u64(rvt: Result<&Node, ConfigerError>) -> Option<&u64> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_u32(rvt: Result<&Node, ConfigerError>) -> Option<&u32> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_i128(rvt: Result<&Node, ConfigerError>) -> Option<&i128> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_i64(rvt: Result<&Node, ConfigerError>) -> Option<&i64> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_int_i32(rvt: Result<&Node, ConfigerError>) -> Option<&i32> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_float64(rvt: Result<&Node, ConfigerError>) -> Option<&f64> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_float32(rvt: Result<&Node, ConfigerError>) -> Option<&f32> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
pub fn try_none(rvt: Result<&Node, ConfigerError>) -> Option<&()> {
match rvt {
Ok(node) => node.into(),
_ => None,
}
}
}