What does Rust’s unary || (parallel pipe) mean?

It is a closure with zero arguments. This is a simplified example to show the basic syntax and usage (play):

fn main() {
    let c = || println!("c called");
    c();
    c();
}

This prints:

c called
c called

Another example from the documentation:

let plus_one = |x: i32| x + 1;

assert_eq!(2, plus_one(1));

Leave a Comment