Hacker News new | past | comments | ask | show | jobs | submit login

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/




&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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: