Skip to main content

HostFn

Struct HostFn 

Source
pub struct HostFn { /* private fields */ }
Expand description

A host function: a native callback the embedder hands the runtime as a value, behind the Rc a Value::HostFn carries.

It is what a builtin is, minus the compile-time enum: a name, an arity, and code. The evaluator gathers arguments against arity and calls f once they are all there, so a host callback is strict and curried like everything else, and the host writes an ordinary Rust closure rather than an application protocol.

The Ctx reaches f so a callback that is handed an Elly callable can call it back (apply_with) under the same id source; without it a closure the callback minted would collide with one the program already holds.

Arity is at least 1. A zero-argument callback could never fire — nothing applies a value to no arguments — so a host that wants a constant supplies the value itself.

Implementations§

Source§

impl HostFn

Source

pub fn new( name: impl Into<Text>, arity: usize, f: impl Fn(&[Value], &Ctx) -> Result<Value, Raised> + 'static, ) -> HostFn

A host function called as name, taking arity arguments.

The name is for rendering and diagnostics only — identity is the allocation, so two HostFns of one name are two functions.

Panics on arity == 0, which is not a function the runtime could ever call (see the type’s docs).

Source

pub fn name(&self) -> &Text

The name the function renders under.

Source

pub fn arity(&self) -> usize

How many arguments it is called with.

Trait Implementations§

Source§

impl Debug for HostFn

The callback is not Debug, so the derive cannot apply; the shape a Value::HostFn shows is its name and arity, which is what identifies it in a dump anyway.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for HostFn

§

impl !RefUnwindSafe for HostFn

§

impl !Send for HostFn

§

impl !Sync for HostFn

§

impl Unpin for HostFn

§

impl UnsafeUnpin for HostFn

§

impl !UnwindSafe for HostFn

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.