Skip to main content

ScriptBuilder

Struct ScriptBuilder 

Source
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

Source

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.

Source

pub fn entry(self, name: impl Into<String>) -> Self

Which in-memory source to start from. Defaults to the first one given.

Source

pub fn file(self, path: impl AsRef<Path>) -> Self

Load from disk instead; imports resolve beside it, as in aura eval.

Source

pub fn allow_env<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

--allow-env=A,B: the named variables only.

Source

pub fn env_values<I, K, V>(self, values: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

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.

Source

pub fn allow_read(self, dir: impl AsRef<Path>) -> Self

--allow-read=<dir>.

Source

pub fn strict(self) -> Self

--strict: warnings fail the load.

Source

pub fn budget(self, budget: Budget) -> Self

The budget each call gets. Loading is held to the same budget.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn load(self) -> Result<Script, Error>

Trait Implementations§

Source§

impl Default for ScriptBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.