Enum ayaka_primitive::RawValue
source · pub enum RawValue {
Unit,
Bool(bool),
Num(i64),
Str(String),
}Expand description
The basic and only type used in scripts.
assert_eq!(serde_yaml::from_str::<RawValue>("~").unwrap(), RawValue::Unit);
assert_eq!(serde_yaml::from_str::<RawValue>("true").unwrap(), RawValue::Bool(true));
assert_eq!(serde_yaml::from_str::<RawValue>("123").unwrap(), RawValue::Num(123));
assert_eq!(serde_yaml::from_str::<RawValue>("\"hello\"").unwrap(), RawValue::Str("hello".to_string()));Variants§
Unit
The unit type. It is empty, just like None or [()] in Rust.
Bool(bool)
The boolean type.
Num(i64)
The number type. It’s i64.
Str(String)
The string type.
Implementations§
source§impl RawValue
impl RawValue
sourcepub fn get_bool(&self) -> bool
pub fn get_bool(&self) -> bool
Gets a boolean from the value:
- A
RawValue::Unitconverts tofalse. - A
RawValue::Numconverts tofalseif and only if it’s zero. - A
RawValue::Strconverts tofalseif and only if it’s empty.
let unit_value = RawValue::Unit;
assert!(!unit_value.get_bool());
let num_value = RawValue::Num(123);
assert!(num_value.get_bool());
let str_value = RawValue::Str("hello".to_string());
assert!(str_value.get_bool());
let empty_str_value = RawValue::Str(String::default());
assert!(!empty_str_value.get_bool());sourcepub fn get_num(&self) -> i64
pub fn get_num(&self) -> i64
Gets a number from the value:
- A
RawValue::Unitconverts to 0. - A
RawValue::Boolconvertsfalseto 0 andtrueto 1. - A
RawValue::Strconverts to the length of the string.
let unit_value = RawValue::Unit;
assert_eq!(unit_value.get_num(), 0);
let bool_value = RawValue::Bool(true);
assert_eq!(bool_value.get_num(), 1);
let str_value = RawValue::Str("hello".to_string());
assert_eq!(str_value.get_num(), 5);sourcepub fn get_str(&self) -> Cow<'_, str>
pub fn get_str(&self) -> Cow<'_, str>
Gets a string from the value:
- A
RawValue::Unitconverts to empty string. - A
RawValue::Boolconverts to “false” or “true”. - A
RawValue::Numconverts to the string representation of the number.
Be careful to use get_str().into_owned(), if possible, use into_str() instead.
let unit_value = RawValue::Unit;
assert_eq!(unit_value.get_str(), "");
let bool_value = RawValue::Bool(true);
assert_eq!(bool_value.get_str(), "true");
let num_value = RawValue::Num(123);
assert_eq!(num_value.get_str(), "123");sourcepub fn into_str(self) -> String
pub fn into_str(self) -> String
Gets a string from the value:
- A
RawValue::Unitconverts to empty string. - A
RawValue::Boolconverts to “false” or “true”. - A
RawValue::Numconverts to the string representation of the number.
Trait Implementations§
source§impl<'de> Deserialize<'de> for RawValue
impl<'de> Deserialize<'de> for RawValue
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for RawValue
impl Ord for RawValue
source§impl PartialEq<RawValue> for RawValue
impl PartialEq<RawValue> for RawValue
source§impl PartialOrd<RawValue> for RawValue
impl PartialOrd<RawValue> for RawValue
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more