4 ms·
People say "Rust has six string types" but what they mean is "the standard library has six string types". Rust-the-language has one string type: str. The standa
by steveklabnik 6y ago
People say "Rust has six string types" but what they mean is "the standard library has six string types". Rust-the-language has one string type: str. The standard library also has:
* String
* OsString / OsStr
* CString / CStr
if people really want to make it look big, they also include PathBuf/Path and Cow<str>.
- deleted 6y ago[deleted]
- iudqnolq 6y agoThanks! I'm definitely often guilty of conflating the stdblib and the language. I prefer to think of it as programers have used strings to represent too many non-string things in the past. It's nice to look at a function sig and see Path/camino::Utf8Path/bytestr::ByteStr and see what they actually plan on doing with it.
- lampe3 6y agoAre there people who don't use the stdlib? and then start to implement things that are in the stdlib?
- steveklabnik 6y agoYes, for example, I am doing embedded development and do not use the standard library at all. There's not a lot of reason to re-implement it, because if you can use it, there's not a lot of reason to not just use it. There are people who make even more string types as packages, and use those. smallstr and bstr are two examples of those.
- lampe3 6y agoSure fair point on embedded devices I can see it. In the context of Backend/Frontend development I would question it. I had a colleague who rewrote some string functions in Java which are part of the stdlib. He called them "Arne Tools". Arne is a name in Germany. We were doing Java Applets back then. I always have to think of that example :D
- steveklabnik 6y agoSure, but just because it’s in the standard library doesn’t mean you use it all the time. 95% of my usage on non-embedded targets is String and &str. The “six string types” makes things seem far more complex than they are.
- iudqnolq 6y agoIt's commonly called no_std, after the attribute #![no_std]. People use it in embedded devices, and they're considering using it in the Linux kernel
- deleted 6y ago[deleted]