Skip to content

struct

Scope

pub struct Scope(/* private */);

An immutable, cheaply clonable set of bindings with an optional parent.

Methods

new

pub fn new() -> Scope

An empty scope.

value

pub fn value(self, name: &str, value: impl Into<Value>) -> Scope

Bind a constant.

signal

pub fn signal<T: Clone + Into<Value> + 'static>(self, name: &str, signal: &Signal<T>) -> Scope

Bind a signal; templates re-render when it changes.

memo

pub fn memo<T: Clone + PartialEq + Into<Value> + 'static>(self, name: &str, memo: &Memo<T>) -> Scope

Bind a memo.

computed

pub fn computed<V: Into<Value>>(self, name: &str, f: impl Fn() -> V + 'static) -> Scope

Bind a value computed on each read.

handler

pub fn handler(self, name: &str, f: impl Fn(&Event) + 'static) -> Scope

Bind an event handler.

function

pub fn function(self, name: &str, f: impl Fn(&[Value]) -> Value + 'static) -> Scope

Bind a function templates can call (slugify(title), or title |> slugify). Keep it pure: the same arguments, the same result, and no changes to state. It takes priority over a standard function of the same name.

function_for

pub fn function_for(&self, name: &str) -> Option<ScopeFunction>

The function bound to name, if any.

child

pub fn child(&self, name: &str, value: Value) -> Scope

A child scope with one extra binding (used for loop variables).

resolve

pub fn resolve(&self, path: &Path) -> Option<Value>

Resolve a path to a value (handlers are not values).

unresolved

pub fn unresolved(&self, path: &Path) -> String

Why path doesn't resolve, for an error: the name isn't bound, or a record on the way has no such field (listing the fields it has, so event.deltaX points at event.delta-x), or isn't a record.

handler_for

pub fn handler_for(&self, path: &Path) -> Option<Handler>

Resolve a single-segment path to a handler.

contains

pub fn contains(&self, name: &str) -> bool

Whether name is bound here or in a parent scope.

names

pub fn names(&self) -> Vec<String>

Every bound name, including inherited ones, sorted.

Trait implementations