Ranges

In a similar way to using |, we can match on a range of values, as follows:

match foo 
{ 
    1 ... 10 => println!("Value between 1 and 10"), 
    _ => println!("Value not between 1 and 10") 
} 

We can use something similar with char, as shown in the following example:

match char_foo 
{ 
    'A' ... 'M' => println!("A - M"), 
    'N' ... 'Y' => println!("N - Y"), 
    'Z' => println!("Z"), 
    _ => println!("something else") 
} 
..................Content has been hidden....................

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