Re:Rust Language Cheat Sheet
by otabdeveloper4 on Sunday April 25, 2021 @08:44AM
(#26932286)
C++ is also 'just "+" them together', and it's not unsafe.
Turns out, it is:
Re:Rust Language Cheat Sheet
by otabdeveloper4 on Sunday April 25, 2021 @09:36AM
(#26932592)
string_view is a new feature designed on purpose to be unsafe.
The idea was to copy slices model from memory safe languages, naturally being C++ with C's influence regarding performance trumps safety, string_view couldn't be made to be as safe as the idea they were copying from.
Another example is span, while C#'s Span and Microsoft's gsl::span do bounds checking, ISO C++17 span naturally leaves it to the developer's responsibility.
Re:Rust Language Cheat Sheet
by otabdeveloper4 on Monday April 26, 2021 @04:15AM
(#26940410)
> The idea was to copy slices model from memory safe languages
No, the idea was to make a simple one-to-one wrapper for the "char, char" pairs programmers were already using all over the place, nothing more.
Concatenating strings in a GC language is easy, you just "+" them together, the cleanup will happen eventually. Concatenating in low-level languages means you have to think about the memory allocation(s) taking place, and the format("{}{}") is a lot more powerful for anything more than just adding two strings. What if you want to prepend "https://"? In GC languages, this might be an extra string being allocated and discarded, in Rust, it's a constant hard-coded into the binary. It just happens that the language has attracted a lot of people who are used to higher-level abstractions due to it's relatively pleasant syntax, type system and abstractions, ecosystem and perfomance.