我正在尝试使用Petgraph的all_simple_paths(),但是我不确定需要什么类型的注释,文档没有给出一个例子。它返回一个impl Iterator<Item = TargetColl>,其中TargetColl: FromIterator<G::NodeId>,但我不知道我应该为它做什么样的注释。
for path in algo::all_simple_paths(&graph, x, y, 0, None) {}error[E0282]: type annotations needed
--> lib.rs:10:29
|
10 | for path in algo::all_simple_paths(&graph, x, y, 0, None) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the element type for this iterator is not specified发布于 2022-10-10 22:07:53
它应该足够使用了
for path in algo::all_simple_paths::<Vec<_>, _>(&graph, x, y, 0, None) {}下面是一个有用的例子:
use petgraph::{algo, prelude::*};
fn main() {
let mut graph = DiGraph::<&str, i32>::new();
let a = graph.add_node("a");
let b = graph.add_node("b");
let c = graph.add_node("c");
let d = graph.add_node("d");
graph.extend_with_edges(&[
(a, b, 1),
(b, c, 1),
(c, d, 1),
(a, b, 1),
(b, d, 1),
]);
let ways = algo::all_simple_paths::<Vec<_>, _>(&graph, a, d, 0, None)
.collect::<Vec<_>>();
assert_eq!(4, ways.len());
}https://stackoverflow.com/questions/67530907
复制相似问题