【问题标题】:What is the stable alternative of to_string()to_string() 的稳定替代品是什么
【发布时间】:2015-01-13 22:41:50
【问题描述】:

我正在通过rust book 工作。在字符串章节中,很多示例使用 to_string() 我的编译器版本(rustc 1.0.0-dev)给出以下警告

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();

代码:

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

我从this question 了解到,这是因为 API 可能会更改,但如果我想将字符串切片 (str&) 转换为字符串,我想知道应该使用什么来代替

【问题讨论】:

  • 我认为目前没有稳定的替代方案!在编译器进入测试版之前,我们将不得不承担这些警告。或者,如果您愿意,也可以禁用警告。
  • 目前range_step 也有类似的警告。这里也没有实际的替换。我想在测试版之前会有一些变化。
  • 这是一个Alpha版本,这意味着整个事情是不稳定的,警告或没有。

标签: rust


【解决方案1】:

您可以解决这些事情,例如format!("Hello"),但我暂时不会打扰。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-22
    • 2011-05-07
    • 2012-04-24
    • 2019-12-03
    • 2010-09-17
    • 2012-03-27
    • 2012-09-30
    • 2010-10-20
    相关资源
    最近更新 更多