pub struct Scope { /* private fields */ }
Expand description
Variables, functions and mixins are defined in a Scope
.
A scope can be a local scope, e.g. in a function, or the global scope. All non-global scopes have a parent. The global scope is global to a sass document, multiple different global scopes may exists in the same rust-language process.
Scopes are often accessed through a ScopeRef
.
Implementations§
source§impl Scope
impl Scope
sourcepub fn new_global(format: Format) -> Self
pub fn new_global(format: Format) -> Self
Create a new global scope.
A “global” scope is just a scope that have no parent. There will be multiple global scopes existing during the evaluation of a single sass file.
sourcepub fn builtin_module(name: &'static str) -> Self
pub fn builtin_module(name: &'static str) -> Self
Create a scope for a built-in module.
sourcepub fn sub_selectors(parent: ScopeRef, selectors: SelectorCtx) -> Self
pub fn sub_selectors(parent: ScopeRef, selectors: SelectorCtx) -> Self
Create a new subscope of a given parent with selectors.
sourcepub fn define_module(&self, name: String, module: ScopeRef)
pub fn define_module(&self, name: String, module: ScopeRef)
Define a module in the scope.
This is used by the @use
statement.
sourcepub fn get_module(&self, name: &str) -> Option<ScopeRef>
pub fn get_module(&self, name: &str) -> Option<ScopeRef>
Get a module.
This is used when refering to a function or variable with namespace.name notation.
sourcepub fn get_format(&self) -> Format
pub fn get_format(&self) -> Format
Get the format used in this scope.
sourcepub fn define(&self, name: Name, val: Value) -> Result<(), ScopeError>
pub fn define(&self, name: Name, val: Value) -> Result<(), ScopeError>
Define a none-default, non-global variable.
sourcepub fn set_variable(
&self,
name: Name,
val: Value,
default: bool,
global: bool
) -> Result<(), ScopeError>
pub fn set_variable( &self, name: Name, val: Value, default: bool, global: bool ) -> Result<(), ScopeError>
Define a variable with a value.
The $
sign is not included in name
.
sourcepub fn define_global(&self, name: Name, val: Value)
pub fn define_global(&self, name: Name, val: Value)
Define a variable in the global scope that is an ultimate parent of this scope.
sourcepub fn get_or_none(&self, name: &Name) -> Option<Value>
pub fn get_or_none(&self, name: &Name) -> Option<Value>
Get the Value for a variable.
sourcepub fn get(&self, name: &Name) -> Result<Value, ScopeError>
pub fn get(&self, name: &Name) -> Result<Value, ScopeError>
Get the value for a variable (or an error).
sourcepub fn store_local_values(&self, names: &[Name]) -> Vec<(Name, Option<Value>)>
pub fn store_local_values(&self, names: &[Name]) -> Vec<(Name, Option<Value>)>
Copy a set of local variables to a temporary holder
sourcepub fn restore_local_values(&self, data: Vec<(Name, Option<Value>)>)
pub fn restore_local_values(&self, data: Vec<(Name, Option<Value>)>)
Restore a set of local variables from a temporary holder
sourcepub fn get_global_or_none(&self, name: &Name) -> Option<Value>
pub fn get_global_or_none(&self, name: &Name) -> Option<Value>
Get the global Value for a variable.
sourcepub fn get_mixin(&self, name: &Name) -> Option<MixinDecl>
pub fn get_mixin(&self, name: &Name) -> Option<MixinDecl>
Get a mixin by name.
Returns the formal args and the body of the mixin.
sourcepub fn define_mixin(&self, name: Name, mixin: MixinDecl)
pub fn define_mixin(&self, name: Name, mixin: MixinDecl)
Define a mixin.
sourcepub fn define_function(&self, name: Name, func: Function)
pub fn define_function(&self, name: Name, func: Function)
Define a function.
sourcepub fn get_function(&self, name: &Name) -> Result<Option<Function>, ScopeError>
pub fn get_function(&self, name: &Name) -> Result<Option<Function>, ScopeError>
Get a function by name.
sourcepub fn get_selectors(&self) -> &SelectorCtx
pub fn get_selectors(&self) -> &SelectorCtx
Get the selectors active for this scope.
sourcepub fn functions_map(&self) -> Value
pub fn functions_map(&self) -> Value
Get the functions of this scope as a Value::Map
.
sourcepub fn variables_map(&self) -> Value
pub fn variables_map(&self) -> Value
Get the variables of this scope as a Value::Map
.
sourcepub fn forward(&self) -> ScopeRef
pub fn forward(&self) -> ScopeRef
Get the forward scope for this scope.
Create a new one if necessary.
sourcepub fn opt_forward(&self) -> Option<ScopeRef>
pub fn opt_forward(&self) -> Option<ScopeRef>
Get the forward scope for this scope, if any.