Besides `String`, what is another way to have an owned string slice in Rust, and why might you choose it?
Go & Rust interview question for Advanced practice.
Answer
Another way to have an owned string slice is Box<str. You can create one from a String by calling .intoboxedstr(). rust let s = String::from("an owned string"); // This consumes the String and creates an owned slice let ownedslice: Box<str = s.intoboxedstr(); You might choose Box<str over String if you have a string that you know will not need to be modified or have its capacity changed after creation. A String always retains its capacity information, making it slightly larger (3 words: pointer, length, capacity) than a Box<str, which is just a fat pointer (2 words: pointer, length). For a large number of immutable, owned strings, using Box<str can be a small memory optimization.
Explanation
Choosing between String and Box<str is a micro-optimization that is usually only relevant in performance-critical applications with a very large number of strings.