4 ms·
Six? I can think of String (owned bag of utf-8 bytes), &str (reference to utf-8 bytes), and OsString (potentially non utf-8 depending on your platform, used for
by iudqnolq 5y ago
Six? I can think of String (owned bag of utf-8 bytes), &str (reference to utf-8 bytes), and OsString (potentially non utf-8 depending on your platform, used for ffi).
Some people say Cow<str> is a string type, but I think it's better thought of as a genetic type you often use with strings.
- steveklabnik 5y agoPeople 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 5y ago[deleted]
- iudqnolq 5y 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 5y agoAre there people who don't use the stdlib? and then start to implement things that are in the stdlib?
- steveklabnik 5y 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 5y 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 5y 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 5y 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 5y ago[deleted]