finally finished slice...
This commit is contained in:
16
notes
16
notes
@ -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)
|
||||
|
Reference in New Issue
Block a user