[][src]Struct boxfnonce::BoxFnOnce

pub struct BoxFnOnce<'a, Arguments, Result = ()>(_);

BoxFnOnce boxes any FnOnce 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, BoxFnOnce tries to provide a safe implementation.

Instead of Box<FnOnce(Args...) -> Result + 'a> (or Box<FnBox(Args...) -> Result> + 'a) the box type is BoxFnOnce<'a, (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 omitted: BoxFnOnce<'a, (Args...,)>.

Internally it is implemented similar to Box<FnBox()>, but there is no FnOnce implementation for BoxFnOnce.

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

If you need to send the FnOnce use SendBoxFnOnce instead.

Examples

Move value into closure and box it:

use boxfnonce::BoxFnOnce;
let s = String::from("foo");
let f : BoxFnOnce<()> = BoxFnOnce::from(|| {
    println!("Got called: {}", s);
    drop(s);
});
f.call();

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

use boxfnonce::BoxFnOnce;
let s = String::from("foo");
let f : BoxFnOnce<(), String> = BoxFnOnce::from(|| {
    println!("Got called: {}", s);
    s
});
assert_eq!(f.call(), "foo".to_string());

Methods

impl<'a, Args, Result> BoxFnOnce<'a, Args, Result>[src]

pub fn call_tuple(self, args: 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 BoxFnOnce<(...), Result> has a separate call method for passing arguments "untupled".

pub fn new<F>(func: F) -> Self where
    Self: From<F>, 
[src]

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

impl<'a, Result> BoxFnOnce<'a, (), Result>[src]

pub fn call(self) -> Result[src]

call inner function, consumes the box.

impl<'a, A1, Result> BoxFnOnce<'a, (A1,), Result>[src]

pub fn call(self, a1: A1) -> Result[src]

call inner function, consumes the box.

impl<'a, A1, A2, Result> BoxFnOnce<'a, (A1, A2), Result>[src]

pub fn call(self, a1: A1, a2: A2) -> Result[src]

call inner function, consumes the box.

impl<'a, A1, A2, A3, Result> BoxFnOnce<'a, (A1, A2, A3), Result>[src]

pub fn call(self, a1: A1, a2: A2, a3: A3) -> Result[src]

call inner function, consumes the box.

impl<'a, A1, A2, A3, A4, Result> BoxFnOnce<'a, (A1, A2, A3, A4), Result>[src]

pub fn call(self, a1: A1, a2: A2, a3: A3, a4: A4) -> Result[src]

call inner function, consumes the box.

impl<'a, A1, A2, A3, A4, A5, Result> BoxFnOnce<'a, (A1, A2, A3, A4, A5), Result>[src]

pub fn call(self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) -> Result[src]

call inner function, consumes the box.

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

pub fn call(self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) -> Result[src]

call inner function, consumes the box.

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

pub fn call(
    self,
    a1: A1,
    a2: A2,
    a3: A3,
    a4: A4,
    a5: A5,
    a6: A6,
    a7: A7
) -> Result
[src]

call inner function, consumes the box.

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

pub fn call(
    self,
    a1: A1,
    a2: A2,
    a3: A3,
    a4: A4,
    a5: A5,
    a6: A6,
    a7: A7,
    a8: A8
) -> Result
[src]

call inner function, consumes the box.

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

pub fn call(
    self,
    a1: A1,
    a2: A2,
    a3: A3,
    a4: A4,
    a5: A5,
    a6: A6,
    a7: A7,
    a8: A8,
    a9: A9
) -> Result
[src]

call inner function, consumes the box.

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

pub fn call(
    self,
    a1: A1,
    a2: A2,
    a3: A3,
    a4: A4,
    a5: A5,
    a6: A6,
    a7: A7,
    a8: A8,
    a9: A9,
    a10: A10
) -> Result
[src]

call inner function, consumes the box.

Trait Implementations

impl<'a, Result, F: 'a + FnOnce() -> Result> From<F> for BoxFnOnce<'a, (), Result>[src]

impl<'a, A1, Result, F: 'a + FnOnce(A1) -> Result> From<F> for BoxFnOnce<'a, (A1,), Result>[src]

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

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

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

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

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

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

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

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

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

impl<'a, Arguments, Result> From<SendBoxFnOnce<'a, Arguments, Result>> for BoxFnOnce<'a, Arguments, Result>[src]

Auto Trait Implementations

impl<'a, Arguments, Result = ()> !Send for BoxFnOnce<'a, Arguments, Result>

impl<'a, Arguments, Result = ()> !Sync for BoxFnOnce<'a, Arguments, Result>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]