pub struct MiraNativeFn { /* private fields */ }Expand description
A named, single-threaded native function callable from MiraScript.
Implementations§
Source§impl MiraNativeFn
impl MiraNativeFn
Sourcepub fn new(
name: impl Into<String>,
callback: impl for<'a> Fn(&mut MiraCallContext<'a>, &[MiraAny]) -> Result<MiraAny> + 'static,
) -> Self
pub fn new( name: impl Into<String>, callback: impl for<'a> Fn(&mut MiraCallContext<'a>, &[MiraAny]) -> Result<MiraAny> + 'static, ) -> Self
Create a native function with the given diagnostic name.
§Examples
use mirascript_vm::{MiraAny, MiraContext, MiraNativeFn, eval};
let mut context = MiraContext::empty();
context.insert_fn("answer", MiraNativeFn::new("host.answer", |_, _| {
Ok(MiraAny::Number(42.0))
}));
assert_eq!(eval("answer()", &context)?, MiraAny::Number(42.0));Trait Implementations§
Source§impl Clone for MiraNativeFn
impl Clone for MiraNativeFn
Source§fn clone(&self) -> MiraNativeFn
fn clone(&self) -> MiraNativeFn
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MiraNativeFn
impl Debug for MiraNativeFn
Source§impl<F> From<F> for MiraNativeFn
impl<F> From<F> for MiraNativeFn
Source§impl From<MiraNativeFn> for MiraAny
impl From<MiraNativeFn> for MiraAny
Source§fn from(value: MiraNativeFn) -> Self
fn from(value: MiraNativeFn) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !RefUnwindSafe for MiraNativeFn
impl !Send for MiraNativeFn
impl !Sync for MiraNativeFn
impl !UnwindSafe for MiraNativeFn
impl Freeze for MiraNativeFn
impl Unpin for MiraNativeFn
impl UnsafeUnpin for MiraNativeFn
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