pub struct Boxed<T>(pub T);
Expand description
Wrapper to extract T
from a JsBox<T>
or create a JsBox
from a T
.
Boxed
is especially useful for exporting async functions and tasks.
struct Greeter {
greeting: String,
}
impl Finalize for Greeter {}
impl Greeter {
fn new(greeting: String) -> Self {
Self { greeting }
}
fn greet(&self, name: &str) -> String {
format!("{}, {name}!", self.greeting)
}
}
#[neon::export]
fn create_greeter(greeting: String) -> Boxed<Arc<Greeter>> {
Boxed(Arc::new(Greeter::new(greeting)))
}
#[neon::export(task)]
fn greet(Boxed(greeter): Boxed<Arc<Greeter>>, name: String) -> String {
greeter.greet(&name)
}
Tuple Fields§
§0: T
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Boxed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Boxed<T>where
T: RefUnwindSafe,
impl<T> Send for Boxed<T>where
T: Send,
impl<T> Sync for Boxed<T>where
T: Sync,
impl<T> Unpin for Boxed<T>where
T: Unpin,
impl<T> UnwindSafe for Boxed<T>where
T: 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