str to string rust code example
Example 1: rust into string
// You can convert a literal string (&str) into a String using the to_string function
// Here s is a String where s_literal is a &'static str
let s_literal = "String literal";
let s = s_literal.to_string();
Example 2: string to str rust
// You cannot convert a String to a str in rust since it is not static
// You can convert a slice of a string to a &str as so:
let string_slice: &str = &s[..];