News for hackers. Stuff that matters.
Re:Why Rust strings seem hard by jeltz on Wednesday April 14, 2021 @04:27PM (#26812596)
Hm, I feel Rust's strings are the easiest I have worked with on any programming language but that might be due to my knowledge of unicode and of C.

The only thing which surprised me was the &str type. Why isn't it just an ordinary struct (called e.g. Str) consisting of a pointer/reference and a length?

Re:Why Rust strings seem hard by kimundi on Wednesday April 14, 2021 @06:56PM (#26814139)
With dynamically sized types like `str`, Rust allows to separate "what kind of pointer + metadata is this" from "what kind of data does it point at". So, for example, you can have the types `str`, `[T]` or `Path`, and can have them behind the pointer types `&T`, `Box<T>` or `Arc<T>`.

If Rust had defined a special struct `Str` for `&str`, then it would have to define special structs for all the combinations possible: Str, ArcSlice, BoxPath, etc.

Re:Why Rust strings seem hard by TheCoelacanth on Wednesday April 14, 2021 @04:35PM (#26812692)
Rust's strings are one of the easiest to use correctly and one of the hardest to use incorrectly, but they vast majority of string handling is done incorrectly, so that makes Rust seem hard.
Re:Why Rust strings seem hard by brundolf on Wednesday April 14, 2021 @04:33PM (#26812669)
Yeah, this article was specifically aimed at people who haven't worked with C/C++, and instead have the higher-level mental model for what strings are and how they work.
Re:Why Rust strings seem hard by steveklabnik on Wednesday April 14, 2021 @04:35PM (#26812701)
I linked to a PR above which implemented this idea, and was rejected.
Re:Why Rust strings seem hard by steveklabnik on Wednesday April 14, 2021 @07:21PM (#26814339)
(see kimundi's answer; I misunderstood what you were asking. I'd have deleted this comment but I don't seem to be able to.)