It's not causing me any difficulties — I am perfectly capable of using String — but is there any reason that str is encapsulated in its own special type rather than inside the more general Box type? If there is a reason then the answer might help me model how to work with Box differently.
Why is str encapsulated inside String instead of inside a Box<str>? Is it simply for convenience of typing such a common structure or is there a deeper reason?
String is more like a Vec<char> than a Box<str> - it has methods to push more chars on the end, or push a whole str. It has length and capacity, rather than only length. Like Box and Vec, it owns it's contents, and places them on the heap; unlike Box, it also extends the functionality of str beyond its inherent properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With