While I was writing a program that works a lot with string, sometimes I got some problems with the way of turn a String
to a &str
.
let some_str = &string[..];
The most common problem is this.
fn main() {
...
// to forget the `[..]` V
let new_static_str = &some_string;
}
Meanwhile, never happened the opposite, I could do any of this to convert a &str
to a String
fn main() {
let static_str = "some text";
let string1 = String::from(static_str);
let string2 = static_str.to_string();
let string3 = static_str.to_owned();
}
When I searched, I only found this way to convert a String
to a &str
.
Today, there is still no built-in function for this?