Struct boxfnonce::SendBoxFnOnce [] [src]

pub struct SendBoxFnOnce<Args, Result = ()> { /* fields omitted */ }

SendBoxFnOnce boxes any FnOnce + Send function up to a certain number of arguments (10 as of now).

As Box<FnOnce()> doesn't work yet, and Box<FnBox()> will not be available in stable rust, SendBoxFnOnce tries to provide a safe implementation.

Instead of Box<FnOnce(Args...) -> Result> (or Box<FnBox(Args...) -> Result>) the box type is SendBoxFnOnce<(Args...,), Result> (the arguments are always given as tuple type). If the function doesn't return a value (i.e. the empty tuple) Result can be ommitted: SendBoxFnOnce<(Args...,)>.

Internally it constructs a FnMut which keeps the FnOnce in an Option, and extracts the FnOnce on the first call.

You can build boxes for diverging functions too, but specifying the type (like SendBoxFnOnce<(), !>) is not possible as the ! type is experimental.

Examples

Move value into closure to return it, box the closure and send it:

use boxfnonce::SendBoxFnOnce;
use std::thread;

let s = String::from("foo");
let f : SendBoxFnOnce<(), String> = SendBoxFnOnce::from(|| {
    println!("Got called: {}", s);
    s
});
let result = thread::Builder::new().spawn(move || {
    f.call()
}).unwrap().join().unwrap();
assert_eq!(result, "foo".to_string());

Methods

impl<Args, Result> SendBoxFnOnce<Args, Result>
[src]

call inner function, consumes the box.

call_tuple can be used if the arguments are available as tuple. Each usable instance of SendBoxFnOnce<(...), Result> has a separate call method for passing arguments "untupled".

SendBoxFnOnce::new is an alias for SendBoxFnOnce::from.

impl<Result> SendBoxFnOnce<(), Result>
[src]

call inner function, consumes the box

impl<A1, Result> SendBoxFnOnce<(A1,), Result>
[src]

call inner function, consumes the box

impl<A1, A2, Result> SendBoxFnOnce<(A1, A2), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, Result> SendBoxFnOnce<(A1, A2, A3), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, Result> SendBoxFnOnce<(A1, A2, A3, A4), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, A6, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5, A6), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, A6, A7, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, A6, A7, A8, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, A6, A7, A8, A9, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8, A9), Result>
[src]

call inner function, consumes the box

impl<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Result> SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), Result>
[src]

call inner function, consumes the box

Trait Implementations

impl<Result, F: 'static + FnOnce() -> Result + Send> From<F> for SendBoxFnOnce<(), Result>
[src]

Performs the conversion.

impl<A1, Result, F: 'static + FnOnce(A1) -> Result + Send> From<F> for SendBoxFnOnce<(A1,), Result>
[src]

Performs the conversion.

impl<A1, A2, Result, F: 'static + FnOnce(A1, A2) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, Result, F: 'static + FnOnce(A1, A2, A3) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, Result, F: 'static + FnOnce(A1, A2, A3, A4) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, A6, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5, A6) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5, A6), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, A6, A7, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5, A6, A7) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, A6, A7, A8, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5, A6, A7, A8) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, A6, A7, A8, A9, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8, A9), Result>
[src]

Performs the conversion.

impl<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Result, F: 'static + FnOnce(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> Result + Send> From<F> for SendBoxFnOnce<(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), Result>
[src]

Performs the conversion.