pub struct With<F, O>(pub F)
where
for<'cx> F: FnOnce(&mut Cx<'cx>) -> O;
Expand description
Wraps a closure that will be lazily evaluated when TryIntoJs::try_into_js
is
called.
Useful for executing arbitrary code on the main thread before returning from a
function exported with neon::export
.
§Example
use std::time::Instant;
#[neon::export(task)]
fn sum(nums: Vec<f64>) -> impl for<'cx> TryIntoJs<'cx> {
let start = Instant::now();
let sum = nums.into_iter().sum::<f64>();
let log = format!("sum took {} ms", start.elapsed().as_millis());
With(move |cx| -> NeonResult<_> {
cx.global::<JsObject>("console")?
.method(cx, "log")?
.arg(&log)?
.exec()?;
Ok(sum)
})
}
Tuple Fields§
§0: F
Trait Implementations§
impl<'cx, F, O> TryIntoArguments<'cx> for With<F, O>
Auto Trait Implementations§
impl<F, O> Freeze for With<F, O>where
F: Freeze,
impl<F, O> RefUnwindSafe for With<F, O>where
F: RefUnwindSafe,
impl<F, O> Send for With<F, O>where
F: Send,
impl<F, O> Sync for With<F, O>where
F: Sync,
impl<F, O> Unpin for With<F, O>where
F: Unpin,
impl<F, O> UnwindSafe for With<F, O>where
F: 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more