Rust: Slice

Andreas
1 min readJul 11, 2020

Slice is a view to a continuous sequence of data in Rust. A good pre-read: Rust: References

Notation

let s = String::from("abcdefg");// grab all data
let slice1 = &s[..];
println!("{}", slice1); // "abcdefg"
// beginning to an exclusive end index
let slice2 = &s[..2];
// between inclusive start index to exclusive end index
let slice3 = &s[0..2];
println!("{} == {}", slice2, slice3); // ab == ab
// from inclusive start index to the end
let slice4 = &s[5..];
println!("{}"…

--

--

Andreas

All opinions are my own, spending life in Software Industry with lovely essence as an Engineer, while assuming roles in various facets of the SDLC process.