finally finished slice...

This commit is contained in:
2022-12-20 09:14:10 -05:00
parent 9bca80091f
commit 8f32bb41ba
3 changed files with 59 additions and 3 deletions

16
notes
View File

@ -214,4 +214,20 @@ slices
reference to a contiguous sequence of elements
enumerate returns a tuple with counter and reference to thing (counter, &thing)
slice is a pointer to a string, with a length
let s = String::from("a a a a");
slice = &s[0..2];
you can drop the first number if it's zero: let slice = &s[..2];
or the last number if it's the end of the string: let slice = &s[4..];
or both numbers to slice the whole thing: let slice = &s[..];
you can not create a slice that starts or ends within multibyte unicode parts
String: a heap allocated vector of bytes that is stored on the heap. It is potentially mutable.
&str: an immutable borrowed string slice.
let s = "string"; // string literal (it's a slice)