use std::collections::HashMap;
use std::fmt::Display;
use std::ops::Deref;
#[derive(Debug, Clone, PartialEq)]
pub enum AamValue {
String(String),
List(Vec<AamValue>),
Object(HashMap<String, AamValue>),
}
impl AamValue {
pub fn as_str(&self) -> Option<&str> {
if let AamValue::String(s) = self {
Some(s)
} else {
None
}
}
pub fn as_list(&self) -> Option<&Vec<AamValue>> {
if let AamValue::List(l) = self {
Some(l)
} else {
None
}
}
pub fn as_object(&self) -> Option<&HashMap<String, AamValue>> {
if let AamValue::Object(o) = self {
Some(o)
} else {
None
}
}
pub fn is_list(&self) -> bool {
matches!(self, AamValue::List(_))
}
pub fn is_object(&self) -> bool {
matches!(self, AamValue::Object(_))
}
}
impl PartialEq<&str> for AamValue {
fn eq(&self, other: &&str) -> bool {
self.as_str().expect("Here must be AamlError") == *other
}
}
impl Display for AamValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str().expect("Here must be AamlError"))
}
}
impl Deref for AamValue {
type Target = str;
fn deref(&self) -> &Self::Target {
self.as_str().expect("Here must be AamlError")
}
}