Struct namable_closures::closures::Closure [−][src]
pub struct Closure<'a, State, Input, Output> where
State: 'a, { /* fields omitted */ }
A Closure owns its state, and only refers to the state when called.
Correspond to unnamable closures like:
ⓘThis example is not tested
|...| { /* only refers captured variables */ }
Example:
let state = 10; let add_ten:Closure<i32,(i32,),i32> = closure!(state=&state => |i| i+10); assert_eq!(add_ten.stable_call((1,)),11); let state = Point::new(10,20); let mut offset:Closure<Point,(i32,i32),Point> = closure!(state=&state => |a,b| Point::new(state.x+a,state.y+b)); let p = offset.stable_call_mut((1i32,2i32)); assert_eq!(p.x,11); assert_eq!(p.y,22);
Methods
impl<'a, State, Input, Output> Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> Closure<'a, State, Input, Output>
pub fn new(f: fn(_: &State, _: Input) -> Output, t: &'a State) -> Self
[src]
pub fn new(f: fn(_: &State, _: Input) -> Output, t: &'a State) -> Self
pub fn call_with_state(&self, s: &State, i: Input) -> Output
[src]
pub fn call_with_state(&self, s: &State, i: Input) -> Output
Trait Implementations
impl<'a, State, Input, Output> Copy for Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> Copy for Closure<'a, State, Input, Output>
impl<'a, State, Input, Output> Clone for Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> Clone for Closure<'a, State, Input, Output>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl<'a, State, Input, Output> StableFnOnce<Input> for Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> StableFnOnce<Input> for Closure<'a, State, Input, Output>
type Output = Output
fn stable_call_once(self, i: Input) -> Output
[src]
fn stable_call_once(self, i: Input) -> Output
impl<'a, State, Input, Output> StableFnMut<Input> for Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> StableFnMut<Input> for Closure<'a, State, Input, Output>
fn stable_call_mut(&mut self, i: Input) -> Output
[src]
fn stable_call_mut(&mut self, i: Input) -> Output
impl<'a, State, Input, Output> StableFn<Input> for Closure<'a, State, Input, Output>
[src]
impl<'a, State, Input, Output> StableFn<Input> for Closure<'a, State, Input, Output>
fn stable_call(&self, i: Input) -> Output
[src]
fn stable_call(&self, i: Input) -> Output