use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SPathType {
Nodes,
Value,
Logical,
}
impl SPathType {
pub fn as_function_arg_type(&self) -> FunctionArgType {
match self {
SPathType::Nodes => FunctionArgType::NodeList,
SPathType::Value => FunctionArgType::Value,
SPathType::Logical => FunctionArgType::Logical,
}
}
}
impl fmt::Display for SPathType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SPathType::Nodes => write!(f, "nodes type"),
SPathType::Logical => write!(f, "logical type"),
SPathType::Value => write!(f, "value type"),
}
}
}
#[doc(hidden)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum FunctionArgType {
Literal,
SingularQuery,
Value,
NodeList,
Logical,
}
impl fmt::Display for FunctionArgType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FunctionArgType::Literal => write!(f, "literal"),
FunctionArgType::SingularQuery => write!(f, "singular query"),
FunctionArgType::Value => write!(f, "value type"),
FunctionArgType::NodeList => write!(f, "node list type"),
FunctionArgType::Logical => write!(f, "logical type"),
}
}
}
impl FunctionArgType {
pub fn converts_to(&self, spath_type: SPathType) -> bool {
matches!(
(self, spath_type),
(
FunctionArgType::Literal | FunctionArgType::Value,
SPathType::Value
) | (
FunctionArgType::SingularQuery,
SPathType::Value | SPathType::Nodes | SPathType::Logical
) | (
FunctionArgType::NodeList,
SPathType::Nodes | SPathType::Logical
) | (FunctionArgType::Logical, SPathType::Logical),
)
}
}