4 ms·
Better analogy is std::string_view vs std::string
by dezgeg 1y ago
Better analogy is std::string_view vs std::string
- School-Cotton 1y agoTechnically that's a bit closer, yes, but way more people have heard of char* than string_view, and char* is similar _enough_ to &str that the analogy still works.
- scotty79 1y agoNah. &str is const char* exactly. It's as primitive as types in rust get.
- tuetuopay 1y agoNope. `&str` includes the length of the slice, which `const char*` does not. `std::string_view` is the proper analogy.
- School-Cotton 1y agoAnother difference is that &str is guaranteed to be utf-8, whereas const char* can be any encoding (or no encoding).
- pdpi 1y agoAlso, &str is closer to const uint8_t* than it is to const char*. Chars are signed by default and are at least 8 bits, but can be wider.