代码如下
fn load_proxies(filename:String)->std::io::Result<Vec<String>>{
let mut proxies:Vec<String>=vec![];
let file=File::open(filename)?;
let reader=BufReader::new(&file);
let mut cnt=0;
let mut handle=vec![];
crossbeam::scope( |scope| {
for x in reader.lines() {
let line = match x {
Ok(t) => t,
Err(e) => return Err(e)
};
let tmp = vec![line.clone()];
handle.push(scope.spawn(move || { check_proxy(line) }));
}
for x in handle{
let res=x.join();
if res.1{
proxies.push(res.0);
}
}
});
Ok(proxies)
}
编译器提示
error[E0308]: mismatched types
--> src\main.rs:392:9
|
392 | / for x in handle{
393 | | let res=x.join();
394 | | if res.1{
395 | | proxies.push(res.0);
396 | | }
397 | | }
| |_________^ expected enum
`std::result::Result`, found ()
|
= note: expected type `std::result::Result<_,std::io::Error>`
found type `()`
问题是我的闭包并没有返回任何东西,而且文档里面的签名也是
pub fn scope<'a, F, R>(f: F) -> R where
F: FnOnce(&Scope<'a>) -> R,
所以哪里有问题?
楼主自己发现问题了……闭包里面确实返回了Result,修改后即可
1
共 1 条评论, 1 页
评论区
写评论哈哈,给力!