[英]Old rust code with string append breaks with nightly
I have a line in some of my older rust code that uses append()
, I checked the recent docs and append seem's to have been removed from std::string::String
. 我的一些旧rust代码中有一行使用了
append()
,我检查了最近的文档,发现append已从std::string::String
删除。 my line of code is: 我的代码行是:
hex_to_bin(x).to_string().append(hex_to_bin(y))
main.rs:34:29: 34:50 error: type `collections::string::String` does not implement any method in scope named `append`
main.rs:34 hex_to_bin(x).to_string().append(hex_to_bin(y))
so according to the docs I thought push_str()
would be the same, but when switched I get 所以根据文档,我认为
push_str()
会是一样的,但是当切换时,我得到
main.rs:34:3: 34:52 error: mismatched types: expected `collections::string::String`, found `()` (expected struct collections::string::String, found ())
main.rs:34 hex_to_bin(x).to_string().push_str(hex_to_bin(y))
how can I convert this line of code correctly? 如何正确转换此行代码?
push_str
is declared as: push_str
声明为:
fn push_str(&mut self, string: &str)
This means it operates on a mutable String, and returns ()
. 这意味着它对可变的String进行操作,并返回
()
。 Without seeing the rest of your code, my guess is that you're trying to pass the result of push_str
to something that is expecting a String - perhaps you're expecting to assign the result to a String? 在没有看到其余代码的情况下,我的猜测是您正在尝试将
push_str
的结果push_str
给期望使用String的对象-也许您期望将结果分配给String? Instead you would want to maintain a mutable String and call push_str
to append the hex_to_bin(y)
to it. 相反,您需要维护一个可变的String并调用
push_str
将hex_to_bin(y)
附加到该hex_to_bin(y)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.