gpt4 book ai didi

rust - 在 Rust 中实现字符串缓冲区的最佳方式是什么?

转载 作者:行者123 更新时间:2023-11-29 07:46:02 26 4
gpt4 key购买 nike

假设我想连续对一个字符串做很多小的添加,最好的方法是什么?有最适合这个的数据类型吗?

最佳答案

使用 String native 类型,它被设计为可变且易于增长。

let mut s = String::new();
s.push_str("GET / HTTP/1.0\r\n");
s.push_str("User-Agent: foobar\r\n"); // Etc etc

关于rust - 在 Rust 中实现字符串缓冲区的最佳方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27372976/

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