Hacker News new | ask | show | jobs
by gridspy 2687 days 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-sl...

https://doc.rust-lang.org/std/slice/

1 comments

&str is not the same as &[char]. &str has the same memory representation as &[u8]. char is four bytes, not one.
Thanks Steve.
No problem! It's an easy mistake to make.