我正在尝试使用petgraph
板条箱在有向图上实现随机游走。
到目前为止,我已经定义了一个RandomWalk
实现该Walker
特征的结构:
extern crate petgraph; // 0.4.13
use petgraph::visit::{GraphBase, Walker};
use petgraph::Direction;
pub struct RandomWalk<G>
where G: GraphBase
{
next: G::NodeId,
}
impl<G> Walker<G> for RandomWalk<G>
where G: GraphBase
{
type Item = G::NodeId;
fn walk_next(&mut self, graph: G) -> Option<Self::Item> {
// Even this deterministic walk does not work:
graph.neighbors_directed(self.next, Direction::Incoming).next()
}
}
但是,我收到错误:
error[E0599]: no method named `neighbors_directed` found for type `G` in the current scope
--> src/lib.rs:50:11
|
50 | graph.neighbors_directed(self.next, Direction::Incoming).next()
| ^^^^^^^^^^^^^^^^^^
|
= note: the method `neighbors_directed` exists but the following trait bounds were not satisfied:
`&G : petgraph::visit::IntoNeighborsDirected`
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `neighbors_directed`, perhaps you need to implement it:
candidate #1: `petgraph::visit::IntoNeighborsDirected`
我真的不明白petgraph
API 是如何工作的,是GraphBase
不是正确的类型?