pub struct Builtin(/* private fields */);Expand description
A function implemented in rust that is accessible from within Sass
§Usage
use grass_compiler::{
sass_value::{ArgumentResult, SassNumber, Value},
Builtin, Options, Result as SassResult, Visitor,
};
// An example function that looks up the length of an array or map and adds 2 to it
fn length(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Value> {
args.max_args(1)?;
let len = args.get_err(0, "list")?.as_list().len();
Ok(Value::Dimension(SassNumber::new_unitless(len + 2)))
}
fn main() {
let options = Options::default().add_custom_fn("length", Builtin::new(length));
let css = grass_compiler::from_string("a { color: length([a, b]); }", &options).unwrap();
assert_eq!(css, "a {\n color: 4;\n}\n");
}Implementations§
Trait Implementations§
impl Eq for Builtin
Auto Trait Implementations§
impl Freeze for Builtin
impl RefUnwindSafe for Builtin
impl Send for Builtin
impl Sync for Builtin
impl Unpin for Builtin
impl UnwindSafe for Builtin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.