在下面的代码片段中,Rust抱怨返回类型不匹配。
let line = String::new(); // assume string has content
let line: String = line.bytes()
.flat_map(|b| {
if b > 0x7F {
format!("M-{}", char::from(b - 0x7F)).bytes()
}
else {
[b].into_iter() // error happens here
}
})
.map(|b| { char::from(b) })
.collect();错误如下:
if和else有不兼容的类型 期望型std::str::Bytes<'_>发现结构std::slice::Iter<'_, u8>
我怎么才能避免这种情况?
https://stackoverflow.com/questions/65554428
复制相似问题