pub struct HostRegistry { /* private fields */ }Expand description
The table of Rust closures a script’s host blocks bind to.
Both halves of the toolchain bind through this one table. The candela
crate’s Engine binds at compile time, against the host signatures a
fresh compile produced; crate::artifact::load_program binds at load
time, against the signatures a .cdlb recorded. The checks are the same in
both cases, so an artifact that loads is bound as strictly as a script that
compiles.
Implementations§
Source§impl HostRegistry
impl HostRegistry
pub fn new() -> HostRegistry
Sourcepub fn register_host_fn<Marker, F>(&mut self, namespace: &str, name: &str, f: F)where
F: IntoHostFn<Marker>,
pub fn register_host_fn<Marker, F>(&mut self, namespace: &str, name: &str, f: F)where
F: IntoHostFn<Marker>,
Registers a typed host function under namespace::name.
The closure may take any combination of i64/i32, f64, bool,
String (or a single &str), Vec<T> and string-keyed map arguments,
and return one of those or (). A closure that can fail returns
Result<T, HostError> instead, and the error is raised in the script
that called it. The derived types are checked against the host block
when the script is bound; a mismatch is an error, never a panic.
Sourcepub fn register_host_fn_typed<F>(
&mut self,
namespace: &str,
name: &str,
arg_types: Vec<HostType>,
ret_type: HostType,
f: F,
)
pub fn register_host_fn_typed<F>( &mut self, namespace: &str, name: &str, arg_types: Vec<HostType>, ret_type: HostType, f: F, )
Registers a host function whose signature is given as data.
The closure takes the arguments as a &[Value] slice, as a variadic one
does, but arg_types and ret_type pin the signature, so the binding is
checked against the host block exactly as register_host_fn is and
the declaration must not use .... This is what a host registers
through when the signature is only known at run time: a plugin table, a
generated binding, anything with no Rust type to derive it from.
Sourcepub fn register_host_fn_variadic<F>(
&mut self,
namespace: &str,
name: &str,
f: F,
)
pub fn register_host_fn_variadic<F>( &mut self, namespace: &str, name: &str, f: F, )
Registers a variadic host function under namespace::name.
The closure receives every argument as a &[Value] slice of any length
and returns one Value, or a HostError to raise in the script that
called it, so arguments of mixed or dynamically-typed shape cross the
boundary without a fixed Rust signature. The host block must declare
the function with a ... argument list, and no arity or per-argument
type checking happens at the call site.
Sourcepub fn bind(
&self,
sigs: &[HostFnSig],
structs: &[Struct],
) -> Result<Vec<Rc<dyn Fn(&[Value]) -> Result<Value, HostError>>>, HostBindError>
pub fn bind( &self, sigs: &[HostFnSig], structs: &[Struct], ) -> Result<Vec<Rc<dyn Fn(&[Value]) -> Result<Value, HostError>>>, HostBindError>
Binds every declared host signature to its registered closure,
returning the dispatchers in host-function id order.
§Errors
Returns HostBindError::Unregistered naming every declared function
with no closure behind it, or HostBindError::SignatureMismatch for
the first closure whose arity or types disagree with the declaration.
Trait Implementations§
Source§impl Default for HostRegistry
impl Default for HostRegistry
Source§fn default() -> HostRegistry
fn default() -> HostRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for HostRegistry
impl !Send for HostRegistry
impl !Sync for HostRegistry
impl !UnwindSafe for HostRegistry
impl Freeze for HostRegistry
impl Unpin for HostRegistry
impl UnsafeUnpin for HostRegistry
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
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);