use super::super::{
super::{dispatch_bindings::*, errors},
math::*,
};
impl Expression {
pub fn cast_i64(&self, name: &str) -> Result<i64, String> {
match self {
Expression::Integer(integer) => Ok(*integer),
_ => Err(errors::not_of_types_for(name, self, &["integer"])),
}
}
pub fn cast_i64_integer(&self, name: &str) -> Result<i64, String> {
match self {
Expression::Integer(integer) => Ok(*integer),
Expression::UnsignedInteger(unsigned_integer) => Ok(into_i64(*unsigned_integer)?),
_ => Err(errors::not_of_types_for(name, self, &["integer", "unsigned integer"])),
}
}
pub fn cast_i32_integer(&self, name: &str) -> Result<i32, String> {
match self {
Expression::Integer(integer) => Ok(into_i32(*integer)?),
Expression::UnsignedInteger(unsigned_integer) => Ok(into_i32(*unsigned_integer)?),
_ => Err(errors::not_of_types_for(name, self, &["integer", "unsigned integer"])),
}
}
pub fn cast_u64(&self, name: &str) -> Result<u64, String> {
match self {
Expression::UnsignedInteger(unsigned_integer) => Ok(*unsigned_integer),
_ => Err(errors::not_of_types_for(name, self, &["unsigned integer"])),
}
}
pub fn cast_u64_integer(&self, name: &str) -> Result<u64, String> {
match self {
Expression::Integer(integer) => Ok(into_u64(*integer)?),
Expression::UnsignedInteger(unsigned_integer) => Ok(*unsigned_integer),
_ => Err(errors::not_of_types_for(name, self, &["integer", "unsigned integer"])),
}
}
pub fn cast_u32_integer(&self, name: &str) -> Result<u32, String> {
match self {
Expression::Integer(integer) => Ok(into_u32(*integer)?),
Expression::UnsignedInteger(unsigned_integer) => Ok(into_u32(*unsigned_integer)?),
_ => Err(errors::not_of_types_for(name, self, &["integer", "unsigned integer"])),
}
}
pub fn cast_f64(&self, name: &str) -> Result<f64, String> {
match self {
Expression::Float(float) => Ok(*float),
_ => Err(errors::not_of_types_for(name, self, &["float"])),
}
}
pub fn cast_bool(&self, name: &str) -> Result<bool, String> {
match self {
Expression::Boolean(boolean) => Ok(*boolean),
_ => Err(errors::not_of_types_for(name, self, &["boolean"])),
}
}
pub fn cast_string(self, name: &str) -> Result<String, String> {
match self {
Expression::Text(text) => Ok(text),
_ => Err(errors::not_of_types_for(name, &self, &["string"])),
}
}
pub fn cast_string_clone(&self, name: &str) -> Result<String, String> {
match self {
Expression::Text(text) => Ok(text.clone()),
_ => Err(errors::not_of_types_for(name, &self, &["string"])),
}
}
pub fn cast_list(&self, name: &str) -> Result<&ListResource, String> {
match self {
Expression::List(list_resource) => Ok(list_resource),
_ => Err(errors::not_of_types_for(name, &self, &["list"])),
}
}
pub fn cast_map(&self, name: &str) -> Result<&MapResource, String> {
match self {
Expression::Map(map_resource) => Ok(map_resource),
_ => Err(errors::not_of_types_for(name, &self, &["map"])),
}
}
pub fn cast_custom(&self, name: &str) -> Result<&CustomResource, String> {
match self {
Expression::Custom(custom_resource) => Ok(custom_resource),
_ => Err(errors::not_of_types_for(name, &self, &["custom data type"])),
}
}
pub fn cast_call(&self, name: &str) -> Result<&CallResource, String> {
match self {
Expression::Call(call_resource) => Ok(call_resource),
_ => Err(errors::not_of_types_for(name, &self, &["call"])),
}
}
}