Ben
Ben

Reputation: 1106

What is the stable alternative of to_string()

I'm working my way through the rust book. In the Strings chapter a lot of the examples use to_string() which my version of the compiler(rustc 1.0.0-dev) gives the following warning

strings.rs:3:23: 3:34 warning: use of unstable item, #[warn(unstable)] on by default
strings.rs:3   let mut s = "Hello".to_string();

Code:

fn main() {
  let mut s = "Hello".to_string();
  println!("{}", s);
}

I understand from this question that this is because the API is likely to change, but I would like to know what I should use instead if I want to convert a string slice (str&) to a String

Upvotes: 1

Views: 992

Answers (1)

Chris Morgan
Chris Morgan

Reputation: 90812

You can work around these things, e.g. format!("Hello"), but I really wouldn’t bother for the moment.

Upvotes: 3

Related Questions