pub struct ScriptBuilder { /* private fields */ }Expand description
Configures a script before it is loaded. Grants have the names and meaning of the CLI’s flags.
Implementations§
Source§impl ScriptBuilder
impl ScriptBuilder
Sourcepub fn source(self, name: impl Into<String>, text: impl Into<String>) -> Self
pub fn source(self, name: impl Into<String>, text: impl Into<String>) -> Self
A source held in memory. Several may be given; imports resolve among them.
Sourcepub fn entry(self, name: impl Into<String>) -> Self
pub fn entry(self, name: impl Into<String>) -> Self
Which in-memory source to start from. Defaults to the first one given.
Sourcepub fn file(self, path: impl AsRef<Path>) -> Self
pub fn file(self, path: impl AsRef<Path>) -> Self
Load from disk instead; imports resolve beside it, as in aura eval.
Sourcepub fn env_values<I, K, V>(self, values: I) -> Self
pub fn env_values<I, K, V>(self, values: I) -> Self
Grant these variables with these values. env() reads them from here
and never from the process, so a host’s own environment cannot leak
into a script that was handed other values - and a test can give a
script any environment without changing the process’s.
Sourcepub fn allow_read(self, dir: impl AsRef<Path>) -> Self
pub fn allow_read(self, dir: impl AsRef<Path>) -> Self
--allow-read=<dir>.
Sourcepub fn budget(self, budget: Budget) -> Self
pub fn budget(self, budget: Budget) -> Self
The budget each call gets. Loading is held to the same budget.
Sourcepub fn pure<Args, F: PureFn<Args>>(self, name: impl Into<String>, f: F) -> Self
pub fn pure<Args, F: PureFn<Args>>(self, name: impl Into<String>, f: F) -> Self
D35: a function the script may call as import "host:geo" as geo …
geo.region(ip), named "geo.region" here. Pure is the host’s
promise that the function is deterministic - the language cannot check
it - and it is what lets the script stay hermetic. Return Option for a
value that may be absent: None reaches the script as null.
Sourcepub fn effect<Args, F: EffectFn<Args>>(
self,
name: impl Into<String>,
f: F,
) -> Self
pub fn effect<Args, F: EffectFn<Args>>( self, name: impl Into<String>, f: F, ) -> Self
D35: a function with an effect - it reads or changes something outside
the script. Registering it is the grant, like allow_env, so the load
is no longer hermetic. Err stops the call with E0008.
Sourcepub fn grant_to_imports(self, name: impl Into<String>) -> Self
pub fn grant_to_imports(self, name: impl Into<String>) -> Self
D35 §3: let imported modules call this host function too. By default only the root module can - a package the script imports does not reach the host’s services unless the host says so, one function at a time.
Sourcepub fn host_call_steps(self, steps: u64) -> Self
pub fn host_call_steps(self, steps: u64) -> Self
D35 §5: what one call to a host function costs, in steps. The default is 100. Time spent inside the host is not measured; this is what bounds a loop of host calls.
Sourcepub fn watch(
self,
interval: Duration,
on_reload: impl Fn(Result<ScriptVersion, Error>) + Send + 'static,
) -> Self
pub fn watch( self, interval: Duration, on_reload: impl Fn(Result<ScriptVersion, Error>) + Send + 'static, ) -> Self
D36: watch the script’s files, and reload when their content changes.
Every interval a thread owned by the script looks at the files; a
change is loaded once the files have been left alone for the settle
period (ScriptBuilder::settle), and
passes every check the first load did. on_reload is told of every
automatic reload - the new version, or why it was refused while the old
one keeps serving - so a failure cannot pass unnoticed. It runs on the
watcher’s thread. Only a script loaded from a file can be watched.
Sourcepub fn settle(self, settle: Duration) -> Self
pub fn settle(self, settle: Duration) -> Self
D36 §6: how long the files must stay unchanged before a watched script reloads them - no write, no change of size or modification time. A file being written is never at rest that long, so it is never loaded half done. The default is two intervals and at least a second; raise it for a slow network share. It may not be shorter than the interval.