Fall through patterns

Let's say that we want to have a fall through construct in the same way as we would have in C:

switch(foo) 
{ 
    case 1: 
    case 2: printf("1 and 2
"); 
            break; 
    case 3: printf("3
"); 
            break; 
} 

We can do this in Rust using the | pattern, which is as follows:

match foo  
{ 
    1 | 2 => println!("1 and 2"), 
    3 => println!("3"), 
    _ => println!("anything else") 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset