Struct namable_closures::closures::ClosureRefMut[][src]

pub struct ClosureRefMut<State, Input, Output> { /* fields omitted */ }

A namable closure that owns its state and can mutate it when called.

Correspond to unnamable closures like:

This example is not tested
 move |...| { /* mutates captured variables */ }

Example:

let mut accumulate:ClosureRefMut<i32,(i32,),i32>
    = closure!(ref mut state=0 => move |c| {*state+=c;*state});
assert_eq!(accumulate.stable_call_mut((1,)),1);
assert_eq!(accumulate.stable_call_once((2,)),3);

Methods

impl<State, Input, Output> ClosureRefMut<State, Input, Output>
[src]

Trait Implementations

impl<State, Input, Output> Copy for ClosureRefMut<State, Input, Output> where
    State: Copy
[src]

impl<State, Input, Output> Clone for ClosureRefMut<State, Input, Output> where
    State: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<State, Input, Output> StableFnOnce<Input> for ClosureRefMut<State, Input, Output>
[src]

impl<State, Input, Output> StableFnMut<Input> for ClosureRefMut<State, Input, Output>
[src]

impl<State, Input, Output> StableFn<Input> for ClosureRefMut<State, Input, Output> where
    State: Copy
[src]

Note we implemented StableFn but not Fn for ClosureRefMut.

The reason is that if we implement Fn in this way it will be chosen to use when called, but its behavour is different than call_mut as it does not actually mutate the state - only a copy of the state was mutated.

This argument does not apply to StableFn, as it is up to the user to decide whether stable_call (do not mutate) or stable_call_mut (do mutate) should be called.

Auto Trait Implementations

impl<State, Input, Output> Send for ClosureRefMut<State, Input, Output> where
    State: Send

impl<State, Input, Output> Sync for ClosureRefMut<State, Input, Output> where
    State: Sync