Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do four consecutive vertical lines mean?

Tags:

syntax

rust

In the following code snippet:

let read_pool = ReadPool::new(
    "readpool",
    &Config::default_for_test(),
    || || Context {}
);

What are the four vertical lines || ||?

like image 456
Lion Li Avatar asked Jun 21 '18 11:06

Lion Li


People also ask

What do vertical lines represent?

Characteristics of Lines Vertical lines are seen as tall and represent grandeur. Horizontal and vertical lines used together in a square or rectangular shape convey structure and represent stability.

What are vertical lines called?

The vertical line in the given graph is called Y-axis. In the Cartesian coordinate system, the vertical reference line is called Y-axis. Was this answer helpful?

What does vertical line mean in discrete math?

The vertical line or bar , |, between a and b is called the pipe. The notation a ∣ b \color{red}{a|b} a∣b is read as “ a divides b“.

What does vertical bar mean in math?

The vertical bar is used as a mathematical symbol in numerous ways: absolute value: , read "the absolute value of x" cardinality: , read "the cardinality of the set S" conditional probability: , reads "the probability of X given Y" determinant: , read "the determinant of the matrix A".


2 Answers

|| represents a lambda taking no arguments.

fn main() {
    let a = || println!("hello");
    let b = || { println!("world") };

    a(); // hello
    b(); // world
}

Two together is a lambda returning another lambda:

fn main() {
    let a = || || println!("hello world");

    let c = a();
    c(); // hello world
}
like image 146
FauxFaux Avatar answered Oct 16 '22 08:10

FauxFaux


In Rust, || introduces a lambda (an unnamed function).

The arguments of the lambda are specified in between the two:

  • |a, b| a + b: a lambda taking 2 arguments a and b and returning their sum,
  • || println!("Hello, World"): a lambda taking no argument and printing "Hello, World!".

Since the body of a lambda is just an expression, it can be another lambda:

  • || || println!("Hello, World"): a lambda taking no argument and returning a lambda taking no argument and printing "Hello, World!".

Therefore, || || Context {} is simply:

  • a lambda taking no argument and returning || Context {},
  • which is a lambda taking no argument and returning an instance of Context.
like image 5
Matthieu M. Avatar answered Oct 16 '22 07:10

Matthieu M.