Ranges

Learned about ranges today

I am using the Zed editor. Built with Rust to be fast. With a vision to change how programmers collaborate.

Code

fn main() {
    let say = "My flowers are beautiful";

    // RangeTo
    println!("{}", &say[..1]);
    //=> M

    // RangeToInclusive
    println!("{}", &say[..=1]);
    //=> My

    // RangeFull
    println!("{}", &say[..]);
    //=> My flowers are beautiful

    // Range
    println!("{}", &say[3..10]);
    //=> flowers

    // RangeFrom
    println!("{}", &say[11..]);
    //=> are beautiful
}

Check it on GitHub.

Last updated