gpt4 book ai didi

rust - to_string() 的稳定替代方案是什么

转载 作者:行者123 更新时间:2023-11-29 08:14:53 29 4
gpt4 key购买 nike

我正在研究 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&) 转换为字符串应该使用什么

最佳答案

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

关于rust - to_string() 的稳定替代方案是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27932840/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com