Created
August 1, 2014 14:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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