fn demo_cell(c: &mut Callbacks) {
    {
        let count = Cell::new(0);
        // Again, we have to move ownership of the `count` into the environment closure.
        c.register(move |val| {
            // In here, all we have is a shared reference of our environment. But that's good enough for the `get` and `set` of the cell!
            let new_count = count.get()+1;
            count.set(new_count);
            println!("Callback 2: {} ({}. time)", val, new_count);
        } );
    }

    c.call(2); c.clone().call(3);
}
// So, let us put our counter in a `Cell`, and replicate the example from the previous part.
So, let us put our counter in a `Cell`, and replicate the example from the previous part.
So let us put our counter in a ` Cell ` and replicate the example from the previous part .
fn demo_cell(c: &mut Callbacks) {
    {
        let count = Cell::new(0);
        // Again, we have to move ownership of the `count` into the environment closure.
        c.register(move |val| {
            // In here, all we have is a shared reference of our environment. But that's good enough for the `get` and `set` of the cell!
            let new_count = count.get()+1;
            count.set(new_count);
            println!("Callback 2: {} ({}. time)", val, new_count);
        } );
    }
    c.call(2); c.clone().call(3);
}
fn demo_cell ( c : & mut Callbacks ) { { let count = Cell :: new ( 0 ) ; // Again, we have to move ownership of the `count` into the environment closure. c . register ( move | val | { // In here, all we have is a shared reference of our environment. But that's good enough for the `get` and `set` of the cell! let new_count = count . get ( ) + 1 ; count . set ( new_count ) ; println ! ( " " val new_count ) ; } ) ; } c . call ( 2 ) ; c . clone ( ) . call ( 3 ) ; }
So, let us put our counter in a `Cell`, and replicate the example from the previous part.
So let us put our counter in a ` Cell ` and replicate the example from the previous part .
c
&mut Callbacks
c
&mut Callbacks