This code:
use std::collections::HashMap;
struct MyNode;
struct MyEdge;
struct Graph<N, E> {
h: HashMap<N, Vec<E>>,
}
type MyGraph = Graph<MyNode, MyEdge>;
fn main() {
let x: MyGraph::N;//XXX
println!("Results:")
}
Fails to compile with the error:
error[E0223]: ambiguous associated type
--> /home/xxx/.emacs.d/rust-playground/at-2017-07-26-164119/snippet.rs:21:12
|
21 | let x: MyGraph::N;
| ^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<Graph<MyNode, MyEdge> as Trait>::N`
Is there any way to get N
type from Graph<MyNode, MyEdge>
?
I created an alias (type =
) to not duplicate node type definitions,
so it would be great at the point marked XXX
I could write not let x: MyNode
but let x: expression with MyGraph as argument
.