Skip to main content

Function

Struct Function 

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

A live script or Rust function kept alive by a Rust handle.

Call it with ordinary Rust arguments using call, or preserve script object identity with call_values. Clones refer to the same function. A handle belongs to one VM, survives module replacement, and becomes invalid after Rustia::reset_decision. Using it with another VM or after reset returns an error.

use rustia::Rustia;

let mut lua = Rustia::builder().build()?;
let exports = lua.load("return { double = function(n) return n * 2 end }").install()?;
let double = exports.function(&mut lua, "double")?;
assert_eq!(double.call::<_, i64>(&mut lua, 21)?, 42);

Implementations§

Source§

impl Function

Source

pub fn as_value(&self) -> LiveValue

Clones the underlying live value handle.

Source

pub fn decision_epoch(&self) -> u64

Returns the decision epoch in which this handle was retained.

Source

pub fn call<Args, Return>( &self, rustia: &mut Rustia, args: Args, ) -> Result<Return>
where Args: IntoRustiaMulti, Return: FromRustiaMulti,

Calls the function with Rust arguments and copies its results into Rust.

Pass () for no arguments or a tuple for multiple arguments. The return type selects the results through FromRustiaMulti. Use call_values for results that cannot be copied into OwnedValue, such as functions or cyclic tables. Every result is copied before selection, including extra results and results discarded by ().

Source

pub fn call_values( &self, rustia: &mut Rustia, args: &[LiveValue], ) -> Result<Vec<LiveValue>>

Calls the function with live arguments and returns live handles for every result.

All handles must belong to this VM and its current decision epoch.

Source

pub fn call_in<C, Args, Return>( &self, invocation: &mut Invocation<'_, C>, args: Args, ) -> Result<Return>
where C: HostSchema, Args: IntoRustiaMulti, Return: FromRustiaMulti,

Calls the function within a typed host invocation’s shared budget.

If argument conversion, execution, or result conversion fails, records staged by this call are discarded. Guest table writes and external host changes are not rolled back by this operation. As with call, every returned value must fit OwnedValue before the requested return type selects or discards results.

Source

pub fn call_values_in<C>( &self, invocation: &mut Invocation<'_, C>, args: &[LiveValue], ) -> Result<Vec<LiveValue>>
where C: HostSchema,

Calls this function with live values inside a typed host invocation.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> FromHostArgument for T
where T: Argument,

Source§

impl<T> IntoHostReturn for T
where T: Return,

Source§

impl<T> IntoHostValue for T
where T: Value,