我想更改以下代码,以避免使用.unwrap或.expect:
thread::scope(|s| {
for name in names {
s.spawn(move |_| {
let path_to_file = format!("{}{}", base, name.as_str());
let path_to_file_written = format!("{}{}", guichetout, name.as_str());
write_file(path_to_file.as_str(), name.as_str(), guichetout)
.expect("cannot write data");
log_hash(&path_to_file_written)
.expect("Cannot write hash !");
});
}
})
.unwrap();我目前使用的是crossbeam_utils::thread,我正在考虑改用人造丝。因此,我需要将此代码更改为具有各种组合子的迭代器。我尝试了很多方法,但都不能正常工作。所以如果有人能帮我,那就太好了。
发布于 2020-06-11 05:43:55
Result并使用?运算符来处理错误。mpsc通道或crossbeam的更快的通道)来发回结果。if let Err(e) = fallible() { channel.send(e) }。在另一个线程上,您可以读取该通道并查看是否收到错误,或者通道已关闭而没有错误到达(成功)。https://stackoverflow.com/questions/61954738
复制相似问题