pub struct SyncFunction(/* private fields */);
Expand description
A callable sync function. This currently only supports a subset of values that are supported by the Vm.
Implementations§
Source§impl SyncFunction
impl SyncFunction
Sourcepub async fn async_send_call<T>(
&self,
args: impl GuardedArgs + Send,
) -> VmResult<T>
pub async fn async_send_call<T>( &self, args: impl GuardedArgs + Send, ) -> VmResult<T>
Perform an asynchronous call over the function which also implements Send.
§Examples
use rune::{Hash, Vm};
use rune::runtime::SyncFunction;
use std::sync::Arc;
let mut sources = rune::sources! {
entry => {
async fn add(a, b) {
a + b
}
pub fn main() { add }
}
};
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let add = vm.call(["main"], ())?;
let add: SyncFunction = rune::from_value(add)?;
let value = add.async_send_call::<u32>((1, 2)).await.into_result()?;
assert_eq!(value, 3);
Sourcepub fn call<T>(&self, args: impl GuardedArgs) -> VmResult<T>where
T: FromValue,
pub fn call<T>(&self, args: impl GuardedArgs) -> VmResult<T>where
T: FromValue,
Perform a call over the function represented by this function pointer.
§Examples
use rune::{Hash, Vm};
use rune::runtime::SyncFunction;
use std::sync::Arc;
let mut sources = rune::sources! {
entry => {
fn add(a, b) {
a + b
}
pub fn main() { add }
}
};
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let add = vm.call(["main"], ())?;
let add: SyncFunction = rune::from_value(add)?;
assert_eq!(add.call::<u32>((1, 2)).into_result()?, 3);
Sourcepub fn type_hash(&self) -> Hash
pub fn type_hash(&self) -> Hash
Type Hash of the underlying function.
§Examples
The type hash of a top-level function matches what you get out of Hash::type_hash.
use rune::{Hash, Vm};
use rune::runtime::SyncFunction;
use std::sync::Arc;
let mut sources = rune::sources! {
entry => {
fn pony() { }
pub fn main() { pony }
}
};
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let pony = vm.call(["main"], ())?;
let pony: SyncFunction = rune::from_value(pony)?;
assert_eq!(pony.type_hash(), Hash::type_hash(["pony"]));
Trait Implementations§
Source§impl FromValue for SyncFunction
impl FromValue for SyncFunction
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Try to convert to the given type, from the given value.
Auto Trait Implementations§
impl Freeze for SyncFunction
impl !RefUnwindSafe for SyncFunction
impl Send for SyncFunction
impl Sync for SyncFunction
impl Unpin for SyncFunction
impl !UnwindSafe for SyncFunction
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
Mutably borrows from an owned value. Read more