3 ms·
Vec<char> or an array for instance - [char; 20] can (automatically) create a "slice" of type &[char]. This is true for all types (not just char). The operator
by gridspy 8y ago
Vec<char> or an array for instance - [char; 20] can (automatically) create a "slice" of type &[char]. This is true for all types (not just char).
The operator for this is for eg l[1..10]. It can also happen automatically.
&str is the same type as &[char] - just a renaming.
Still learning Rust myself, apologies if this leads you astray. Just do some reading on slices.
https://doc.rust-lang.org/book/ch04-03-slices.html#string-slices https://doc.rust-lang.org/book/ch04-03-slices.html#string-sl...
https://doc.rust-lang.org/std/slice/ https://doc.rust-lang.org/std/slice/
- steveklabnik 8y ago&str is not the same as &[char]. &str has the same memory representation as &[u8]. char is four bytes, not one.
- gridspy 8y agoThanks Steve.
- steveklabnik 8y agoNo problem! It's an easy mistake to make.