pub const MAX_RANGE_LENGTH: usize = 1_000_000;
pub const MAX_LIST_EXPRESSION_WORK: usize = 10_000_000;
pub const MAX_UNACCOUNTED_LIST_BYTES: usize = 64 * 1024 * 1024;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum ListFunction {
Size,
Head,
Last,
Tail,
Reverse,
Range,
Append,
}
impl ListFunction {
pub const ALL: [Self; 7] = [
Self::Size,
Self::Head,
Self::Last,
Self::Tail,
Self::Reverse,
Self::Range,
Self::Append,
];
pub fn from_function_name(name: &str) -> Option<Self> {
Self::ALL
.into_iter()
.find(|function| name.eq_ignore_ascii_case(function.function_name()))
}
pub const fn function_name(self) -> &'static str {
match self {
Self::Size => "size",
Self::Head => "head",
Self::Last => "last",
Self::Tail => "tail",
Self::Reverse => "reverse",
Self::Range => "range",
Self::Append => "list_append",
}
}
pub const fn arity(self) -> (usize, usize) {
match self {
Self::Range => (2, 3),
Self::Append => (2, 2),
_ => (1, 1),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn function_names_round_trip_case_insensitively() {
for function in ListFunction::ALL {
assert_eq!(
ListFunction::from_function_name(&function.function_name().to_uppercase()),
Some(function)
);
}
assert_eq!(ListFunction::from_function_name("collect"), None);
assert_eq!(ListFunction::Range.arity(), (2, 3));
assert_eq!(ListFunction::Size.arity(), (1, 1));
}
}