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,
) -> Result<T, VmError>
pub async fn async_send_call<T>( &self, args: impl GuardedArgs + Send, ) -> Result<T, VmError>
Perform an asynchronous call over the function which also implements Send.
§Examples
use rune::runtime::SyncFunction;
use rune::sync::Arc;
use rune::{Hash, Vm};
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 unit = Arc::try_new(unit)?;
let mut vm = Vm::without_runtime(unit)?;
let add = vm.call(["main"], ())?;
let add: SyncFunction = rune::from_value(add)?;
let value = add.async_send_call::<u32>((1, 2)).await?;
assert_eq!(value, 3);Sourcepub fn call<T>(&self, args: impl GuardedArgs) -> Result<T, VmError>where
T: FromValue,
pub fn call<T>(&self, args: impl GuardedArgs) -> Result<T, VmError>where
T: FromValue,
Perform a call over the function represented by this function pointer.
§Examples
use rune::runtime::SyncFunction;
use rune::sync::Arc;
use rune::{Hash, Vm};
let mut sources = rune::sources! {
entry => {
fn add(a, b) {
a + b
}
pub fn main() { add }
}
};
let unit = rune::prepare(&mut sources).build()?;
let unit = Arc::try_new(unit)?;
let mut vm = Vm::without_runtime(unit)?;
let add = vm.call(["main"], ())?;
let add: SyncFunction = rune::from_value(add)?;
assert_eq!(add.call::<u32>((1, 2))?, 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::runtime::SyncFunction;
use rune::sync::Arc;
use rune::{Hash, Vm};
let mut sources = rune::sources! {
entry => {
fn pony() { }
pub fn main() { pony }
}
};
let unit = rune::prepare(&mut sources).build()?;
let unit = Arc::try_new(unit)?;
let mut vm = Vm::without_runtime(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 Forget for SyncFunction
impl Freeze for SyncFunctionwhere
*const () is !null: Freeze,
&'static FunctionHandlerVTable: Freeze,
*const ArcInner<RuntimeContext> is !null: Freeze,
PhantomData<ArcInner<RuntimeContext>>: Freeze,
*const ArcInner<Unit> is !null: Freeze,
PhantomData<ArcInner<Unit>>: Freeze,
(): Freeze,
*const [ConstValueBuf] is !null: Freeze,
PhantomData<[ConstValueBuf]>: Freeze,
*const ArcInner<Rtti> is !null: Freeze,
PhantomData<ArcInner<Rtti>>: Freeze,
impl Move for SyncFunction
impl RefUnwindSafe for SyncFunctionwhere
Atomic<usize>: RefUnwindSafe,
NonZero<usize>: RefUnwindSafe,
String: RefUnwindSafe,
(): RefUnwindSafe,
impl Send for SyncFunctionwhere
FunctionHandler: Send,
Arc<RuntimeContext>: Send,
Arc<Unit>: Send,
(): Send,
Unique<[ConstValueBuf]>: Send,
Arc<Rtti>: Send,
impl Sync for SyncFunctionwhere
FunctionHandler: Sync,
Arc<RuntimeContext>: Sync,
Arc<Unit>: Sync,
(): Sync,
Unique<[ConstValueBuf]>: Sync,
Arc<Rtti>: Sync,
impl Unpin for SyncFunctionwhere
*const () is !null: Unpin,
&'static FunctionHandlerVTable: Unpin,
*const ArcInner<RuntimeContext> is !null: Unpin,
Align8<usize>: Unpin,
*const u8 is !null: Unpin,
Box<str>: Unpin,
Box<[u8]>: Unpin,
Box<[Box<str>]>: Unpin,
Box<[ConstNode]>: Unpin,
&'static ConstConstructVtable: Unpin,
*const ArcInner<Unit> is !null: Unpin,
*const Inst is !null: Unpin,
NonZero<usize>: Unpin,
*const Arc<StaticString> is !null: Unpin,
*const ArcInner<StaticString> is !null: Unpin,
*const Vec<u8> is !null: Unpin,
*const Box<[String]> is !null: Unpin,
Box<[String]>: Unpin,
*const Arc<[Address]> is !null: Unpin,
*const ArcInner<[Address]> is !null: Unpin,
*const ArcInner<Rtti> is !null: Unpin,
*const Option<ConstValueBuf> is !null: Unpin,
Box<DebugInfo>: Unpin,
(): Unpin,
Box<[ConstValueBuf]>: Unpin,
impl UnsafeUnpin for SyncFunctionwhere
*const () is !null: UnsafeUnpin,
&'static FunctionHandlerVTable: UnsafeUnpin,
*const ArcInner<RuntimeContext> is !null: UnsafeUnpin,
PhantomData<ArcInner<RuntimeContext>>: UnsafeUnpin,
*const ArcInner<Unit> is !null: UnsafeUnpin,
PhantomData<ArcInner<Unit>>: UnsafeUnpin,
(): UnsafeUnpin,
*const [ConstValueBuf] is !null: UnsafeUnpin,
PhantomData<[ConstValueBuf]>: UnsafeUnpin,
*const ArcInner<Rtti> is !null: UnsafeUnpin,
PhantomData<ArcInner<Rtti>>: UnsafeUnpin,
impl UnwindSafe for SyncFunctionwhere
NonNull<()>: UnwindSafe,
&'static FunctionHandlerVTable: UnwindSafe,
Arc<RuntimeContext>: UnwindSafe,
Arc<Unit>: UnwindSafe,
(): UnwindSafe,
NonNull<[ConstValueBuf]>: UnwindSafe,
NonNull<str>: UnwindSafe,
NonNull<[u8]>: UnwindSafe,
NonNull<[Box<str>]>: UnwindSafe,
NonNull<[ConstNode]>: UnwindSafe,
Arc<Rtti>: UnwindSafe,
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