2 ms·
What's the alternative? If there was just one string type, "str", then you would have to implement your own "String" anyway for any strings you intend to manipu
by unclad5968 4y ago
What's the alternative? If there was just one string type, "str", then you would have to implement your own "String" anyway for any strings you intend to manipulate.
Computers are complex. Sometimes you need a heap allocated vector of bytes, and sometimes you need a heap allocated array of bytes.
- SAI_Peregrinus 4y agoAnd sometimes you need to interact with an OS that uses ASCII for strings, and sometimes one that uses UTF-8, and sometimes one that uses UCS-2, and maybe (if you've been very bad and need to use an IBM Z) to one that uses EBCDIC or something even worse. C defines a string as just a bunch of bytes that represent some text (no embedded NULLs). Rust defines a string (in general) as just a bunch of bytes that represent some text in some encoding specified by the specific string type. So even without the stack vs heap distinction you'd still have tons of string types, because there are tons of string encodings.