operator

Rust open-ended ranges: select a prefix or suffix

Omitting an endpoint constructs a different range type. With array slices these forms select a suffix, prefix, whole sequence or inclusive prefix. Expected output (not executed): [12, 16] [4, 8] [4, 8, 12, 16] [4, 8] Why: Omitted endpoints select to the available boundary of the array in these slice expressions. Common mistake: Not every range form is directly iterable; an out-of-bounds slice can panic. Advanced connection: RangeFrom, RangeTo, RangeFull, RangeToInclusive.

Formal Syntax & Structure

rust syntaxrust
start..; ..end; ..; ..=end

Working Example

Example Snippetrust
fn main() {    let readings = [4, 8, 12, 16];    println!("{:?}", &readings[2..]);    println!("{:?}", &readings[..2]);    println!("{:?}", &readings[..]);    println!("{:?}", &readings[..=1]);}
Rust Reference