Skip to content

Instantly share code, notes, and snippets.

@MatejLach
Created August 1, 2014 14:53
Show Gist options
  • Save MatejLach/fa401df0100d1b721221 to your computer and use it in GitHub Desktop.
Save MatejLach/fa401df0100d1b721221 to your computer and use it in GitHub Desktop.
An example of how to convert a &'static str to a String in Rust
fn main() {
// Example of a &str to a String conversion
use std::str;
let str_slice = "Here is a \"&'static str\"";
let str_repl = str::replace(str_slice, "is", "was"); // String replacement
println!("{}, now it's a \"String\".", str_repl.to_string()); // String conversion
// To go from a String to a &str, use the as_slice() method.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment