Types 锈迹斑斑;类型中包括哪些类型';名称空间?

Types 锈迹斑斑;类型中包括哪些类型';名称空间?,types,rust,petgraph,Types,Rust,Petgraph,我正在研究库的源代码,但找不到类型Graph::NodeId的来源 我可以看到该函数接受类型G(可以是a)astar要求在G的命名空间中有一个类型NodeId pub fn astar( 图:G, 开始:G::NodeId, is_目标:IsGoal, 边缘成本:F, 估计成本:H )->选项在哪里 G:IntoEdge+可访问, IsGoal:FnMut(G::NodeId)->bool, G::NodeId:Eq+Hash, F:FnMut(G::EdgeRef)->K, H:FnMut(G

我正在研究库的源代码,但找不到类型
Graph::NodeId
的来源

我可以看到该函数接受类型
G
(可以是a)
astar
要求在
G
的命名空间中有一个类型
NodeId

pub fn astar(
图:G,
开始:G::NodeId,
is_目标:IsGoal,
边缘成本:F,
估计成本:H
)->选项在哪里
G:IntoEdge+可访问,
IsGoal:FnMut(G::NodeId)->bool,
G::NodeId:Eq+Hash,
F:FnMut(G::EdgeRef)->K,
H:FnMut(G::NodeId)->K,
K:测量+复制,
我可以看出,这被定义为

pub结构图{
节点:Vec,
优势:Vec,
泰:幻影数据,
}
但是,我不知道类型
NodeId
来自何处。我在源代码中看到它定义的唯一地方是trait实现

impl
其中Ix:IndexType,
{
类型NodeId=NodeIndex;
类型EdgeId=EdgeIndex;
类型重量=E;
fn source(&self)->self::NodeId{self.node[0]}
fn目标(&self)->self::NodeId{self.node[1]}
fn权重(&self)->&E{self.weight}
fn id(&self)->self::EdgeId{self.index}
}

但我不明白该类型如何进入
Graph
astar
下的范围,astar有一个绑定
G:intoEdge+visibable
,其中
visibable
定义为

pub trait Visitable:GraphBase{…}
GraphBase
被定义为

pub-trait-GraphBase{
类型EdgeId:Copy+PartialEq;
类型NodeId:Copy+PartialEq;
}
这就是允许
astar
使用
G::NodeId
的原因。基本上你有:

struct Graph;

trait GraphBase {
    type Type;
}

trait Visitable: GraphBase {}

impl GraphBase for Graph {
    type Type = u8;
}

impl Visitable for Graph {}

fn foo<G: Visitable>(_: G, _: G::Type) {}

fn main() {
    foo(Graph, 42);
}
struct图;
性状葡萄糖酶{
类型;
}
可访问特征:GraphBase{}
图形的impl GraphBase{
类型=u8;
}
图{}的impl Visitable
fn foo({uo:G,{uo:G::Type){}
fn main(){
foo(图42);
}
()