use crate::{Date, DateTime, Time};
use raystack_core::{
Coord, Hayson, Marker, Na, Number, Ref, RemoveMarker, Symbol, Uri, Xstr,
};
use serde_json::Value;
pub trait ValueExt {
fn as_hs_coord(&self) -> Option<Coord>;
fn as_hs_date(&self) -> Option<Date>;
fn as_hs_date_time(&self) -> Option<DateTime>;
fn as_hs_marker(&self) -> Option<Marker>;
fn as_hs_na(&self) -> Option<Na>;
fn as_hs_number(&self) -> Option<Number>;
fn as_hs_ref(&self) -> Option<Ref>;
fn as_hs_remove_marker(&self) -> Option<RemoveMarker>;
fn as_hs_str(&self) -> Option<&str>;
fn as_hs_symbol(&self) -> Option<Symbol>;
fn as_hs_time(&self) -> Option<Time>;
fn as_hs_uri(&self) -> Option<Uri>;
fn as_hs_xstr(&self) -> Option<Xstr>;
fn is_hs_coord(&self) -> bool;
fn is_hs_date(&self) -> bool;
fn is_hs_date_time(&self) -> bool;
fn is_hs_marker(&self) -> bool;
fn is_hs_na(&self) -> bool;
fn is_hs_number(&self) -> bool;
fn is_hs_ref(&self) -> bool;
fn is_hs_remove_marker(&self) -> bool;
fn is_hs_str(&self) -> bool;
fn is_hs_symbol(&self) -> bool;
fn is_hs_time(&self) -> bool;
fn is_hs_uri(&self) -> bool;
fn is_hs_xstr(&self) -> bool;
}
impl ValueExt for Value {
fn as_hs_coord(&self) -> Option<Coord> {
Coord::from_hayson(self).ok()
}
fn as_hs_date(&self) -> Option<Date> {
Date::from_hayson(self).ok()
}
fn as_hs_date_time(&self) -> Option<DateTime> {
DateTime::from_hayson(self).ok()
}
fn as_hs_marker(&self) -> Option<Marker> {
Marker::from_hayson(self).ok()
}
fn as_hs_na(&self) -> Option<Na> {
Na::from_hayson(self).ok()
}
fn as_hs_number(&self) -> Option<Number> {
Number::from_hayson(self).ok()
}
fn as_hs_ref(&self) -> Option<Ref> {
Ref::from_hayson(self).ok()
}
fn as_hs_remove_marker(&self) -> Option<RemoveMarker> {
RemoveMarker::from_hayson(self).ok()
}
fn as_hs_str(&self) -> Option<&str> {
self.as_str()
}
fn as_hs_symbol(&self) -> Option<Symbol> {
Symbol::from_hayson(self).ok()
}
fn as_hs_time(&self) -> Option<Time> {
Time::from_hayson(self).ok()
}
fn as_hs_uri(&self) -> Option<Uri> {
Uri::from_hayson(self).ok()
}
fn as_hs_xstr(&self) -> Option<Xstr> {
Xstr::from_hayson(self).ok()
}
fn is_hs_coord(&self) -> bool {
self.as_hs_coord().is_some()
}
fn is_hs_date(&self) -> bool {
self.as_hs_date().is_some()
}
fn is_hs_date_time(&self) -> bool {
self.as_hs_date_time().is_some()
}
fn is_hs_marker(&self) -> bool {
self.as_hs_marker().is_some()
}
fn is_hs_na(&self) -> bool {
self.as_hs_na().is_some()
}
fn is_hs_number(&self) -> bool {
self.as_hs_number().is_some()
}
fn is_hs_ref(&self) -> bool {
self.as_hs_ref().is_some()
}
fn is_hs_remove_marker(&self) -> bool {
self.as_hs_remove_marker().is_some()
}
fn is_hs_str(&self) -> bool {
self.as_hs_str().is_some()
}
fn is_hs_symbol(&self) -> bool {
self.as_hs_symbol().is_some()
}
fn is_hs_time(&self) -> bool {
self.as_hs_time().is_some()
}
fn is_hs_uri(&self) -> bool {
self.as_hs_uri().is_some()
}
fn is_hs_xstr(&self) -> bool {
self.as_hs_xstr().is_some()
}
}