Skip to main content

Crate closure_it

Crate closure_it 

Source
Expand description

Like kotlin it keyword, translate it to closure

§Examples

#[closure_it::closure_it]
fn main() {
    assert_eq!([0i32, 1, 2].map(it+2), [2, 3, 4]);
    assert_eq!([0i32, -1, 2].map(it.abs()), [0, 1, 2]);
    assert_eq!(Some(2).map_or(3, it*2), 4);
}
#[closure_it::closure_it(this)]
fn main() {
    assert_eq!([0i32, 1, 2].map(this+2), [2, 3, 4]);
    assert_eq!([0i32, -1, 2].map(this.abs()), [0, 1, 2]);
    assert_eq!(Some(2).map_or(3, this*2), 4);
}

Attribute Macros§

closure_it
Replace it to closure body, expand the closure parameter after , ; => and (