grass/src/builtin/mod.rs

55 lines
1.2 KiB
Rust
Raw Normal View History

use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
2020-01-25 20:58:30 -05:00
2020-01-25 23:33:45 -05:00
use crate::args::CallArgs;
use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::Selector;
2020-01-25 20:58:30 -05:00
use crate::value::Value;
2020-02-03 07:11:35 -05:00
#[macro_use]
mod macros;
2020-02-02 22:33:04 -05:00
2020-01-25 23:33:45 -05:00
mod color;
2020-02-02 18:05:36 -05:00
mod list;
mod map;
mod math;
mod meta;
mod selector;
mod string;
2020-01-25 23:33:45 -05:00
pub(crate) type GlobalFunctionMap = HashMap<&'static str, Builtin>;
static FUNCTION_COUNT: AtomicUsize = AtomicUsize::new(0);
// TODO: impl Fn
#[derive(Clone)]
pub(crate) struct Builtin(
pub fn(CallArgs, &Scope, &Selector) -> SassResult<Value>,
usize,
);
impl Builtin {
pub fn new(body: fn(CallArgs, &Scope, &Selector) -> SassResult<Value>) -> Builtin {
let count = FUNCTION_COUNT.fetch_add(1, Ordering::Relaxed);
Self(body, count)
}
}
impl PartialEq for Builtin {
fn eq(&self, other: &Self) -> bool {
self.1 == other.1
}
}
2020-01-25 20:58:30 -05:00
pub(crate) static GLOBAL_FUNCTIONS: Lazy<GlobalFunctionMap> = Lazy::new(|| {
let mut m = HashMap::new();
color::register(&mut m);
list::register(&mut m);
2020-03-30 15:43:15 -04:00
map::register(&mut m);
math::register(&mut m);
meta::register(&mut m);
string::register(&mut m);
m
});