1
0
dust/src/built_in_identifiers.rs

52 lines
1.6 KiB
Rust
Raw Normal View History

2024-02-15 21:30:47 +00:00
use std::sync::{Arc, OnceLock};
2024-02-15 20:20:29 +00:00
use enum_iterator::{all, Sequence};
use crate::Identifier;
pub fn all_built_in_identifiers() -> impl Iterator<Item = BuiltInIdentifier> {
all()
}
2024-02-15 21:30:47 +00:00
static OPTION: OnceLock<Identifier> = OnceLock::new();
static NONE: OnceLock<Identifier> = OnceLock::new();
2024-02-15 22:04:34 +00:00
static SOME: OnceLock<Identifier> = OnceLock::new();
static RESULT: OnceLock<Identifier> = OnceLock::new();
static OK: OnceLock<Identifier> = OnceLock::new();
static ERROR: OnceLock<Identifier> = OnceLock::new();
2024-02-15 20:20:29 +00:00
2024-02-15 21:30:47 +00:00
#[derive(Sequence, Debug)]
2024-02-15 20:20:29 +00:00
pub enum BuiltInIdentifier {
Option,
None,
2024-02-15 22:04:34 +00:00
Some,
Result,
Ok,
Error,
2024-02-15 20:20:29 +00:00
}
impl BuiltInIdentifier {
2024-02-15 22:04:34 +00:00
pub fn get(&self) -> &Identifier {
2024-02-15 20:20:29 +00:00
match self {
2024-02-15 22:04:34 +00:00
BuiltInIdentifier::Option => {
OPTION.get_or_init(|| Identifier::from_raw_parts(Arc::new("Option".to_string())))
}
BuiltInIdentifier::None => {
NONE.get_or_init(|| Identifier::from_raw_parts(Arc::new("None".to_string())))
}
BuiltInIdentifier::Some => {
SOME.get_or_init(|| Identifier::from_raw_parts(Arc::new("Some".to_string())))
}
BuiltInIdentifier::Result => {
RESULT.get_or_init(|| Identifier::from_raw_parts(Arc::new("Result".to_string())))
}
BuiltInIdentifier::Ok => {
OK.get_or_init(|| Identifier::from_raw_parts(Arc::new("Ok".to_string())))
}
BuiltInIdentifier::Error => {
ERROR.get_or_init(|| Identifier::from_raw_parts(Arc::new("Error".to_string())))
}
2024-02-15 20:20:29 +00:00
}
}
}