1
0
dust/src/built_in_identifiers.rs

30 lines
685 B
Rust
Raw Normal View History

2024-02-15 20:20:29 +00:00
use std::sync::OnceLock;
use enum_iterator::{all, Sequence};
use crate::Identifier;
pub fn all_built_in_identifiers() -> impl Iterator<Item = BuiltInIdentifier> {
all()
}
const OPTION: OnceLock<Identifier> = OnceLock::new();
const NONE: OnceLock<Identifier> = OnceLock::new();
#[derive(Sequence)]
pub enum BuiltInIdentifier {
Option,
None,
}
impl BuiltInIdentifier {
pub fn get(&self) -> &Identifier {
match self {
BuiltInIdentifier::Option => {
return OPTION.get_or_init(|| Identifier::new("Option"));
}
BuiltInIdentifier::None => return NONE.get_or_init(|| Identifier::new("None")),
}
}
}