RUST compilation error: Expecting `::` instead got `{`
RUST compilation error: Expecting `::` instead got `{`
我是 Rust 的新手,我正在尝试用这个函数编译我的代码:
fn recieve(&mut self, timeout: u64) -> <Vec<Vec<u8>>> {
let mut bufs: Vec<Vec<u8>> = self.streams.iter().map(|_| Vec::new()).collect();
task::block_on(future::join_all(self.streams.iter_mut().zip(bufs.iter_mut()).map(|(s, b)| {
io::timeout(Duration::from_secs(timeout), s.read_to_end(b))
})));
Ok(bufs)
}
我收到这个错误:
error: expected `::`, found `{`
--> src/lib.rs:60:59
|
60 | fn recieve(&mut self, timeout: u64) -> <Vec<Vec<u8>>> {
| ^ expected `::`
这是什么问题?有人能指出我正确的方向吗?
去掉 return 类型周围的尖括号,你应该可以解决这个问题。
尖括号仅在类型中用于包围提供给泛型类型的参数 - 它们不能包围任何类型,就像圆括号可以包围任何表达式一样。
我是 Rust 的新手,我正在尝试用这个函数编译我的代码:
fn recieve(&mut self, timeout: u64) -> <Vec<Vec<u8>>> {
let mut bufs: Vec<Vec<u8>> = self.streams.iter().map(|_| Vec::new()).collect();
task::block_on(future::join_all(self.streams.iter_mut().zip(bufs.iter_mut()).map(|(s, b)| {
io::timeout(Duration::from_secs(timeout), s.read_to_end(b))
})));
Ok(bufs)
}
我收到这个错误:
error: expected `::`, found `{`
--> src/lib.rs:60:59
|
60 | fn recieve(&mut self, timeout: u64) -> <Vec<Vec<u8>>> {
| ^ expected `::`
这是什么问题?有人能指出我正确的方向吗?
去掉 return 类型周围的尖括号,你应该可以解决这个问题。
尖括号仅在类型中用于包围提供给泛型类型的参数 - 它们不能包围任何类型,就像圆括号可以包围任何表达式一样。