←back to thread

452 points birdculture | 1 comments | | HN request time: 0s | source
Show context
baalimago ◴[] No.43981145[source]
>For instance, why do you have to call to_string() on a thing that’s already a string?

It's so hard for me to take Rust seriously when I have to find out answers to unintuitive question like this

replies(7): >>43981274 #>>43981417 #>>43981621 #>>43981663 #>>43981709 #>>43981713 #>>43982610 #
umanwizard ◴[] No.43981709[source]
I’m not sure why it’s counterintuitive that &str and String are different things. Do you also find it counterintuitive in C++ that std::string is different from const char* ? What about &[u8] and Vec<u8> ?
replies(1): >>43982037 #
dezgeg ◴[] No.43982037[source]
Better analogy is std::string_view vs std::string
replies(2): >>43982531 #>>43986461 #
1. umanwizard ◴[] No.43986461[source]
Technically 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.