1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
use daggy;
use position::{Axis, Depth, Rect};
use self::index_map::IndexMap;
use std::any::Any;
use std::iter;
use std::ops::{Index, IndexMut};
use std::option;
use widget::{self, Widget};
pub use daggy::Walker;
pub use self::depth_order::DepthOrder;
pub use self::index_map::GraphIndex;
pub mod algo;
pub mod depth_order;
mod index_map;
pub type NodeIndex = daggy::NodeIndex<u32>;
pub type EdgeIndex = daggy::EdgeIndex<u32>;
pub type IndexPair = (EdgeIndex, NodeIndex);
pub type Parents = daggy::Parents<Node, Edge, u32>;
pub type Children = daggy::Children<Node, Edge, u32>;
pub type PositionParents<I> = iter::Chain<option::IntoIter<I>, option::IntoIter<I>>;
pub type FilteredChildren =
daggy::walker::Filter<Children, fn(&Graph, EdgeIndex, NodeIndex) -> bool>;
pub type DepthChildren = FilteredChildren;
pub type XPositionChildren = FilteredChildren;
pub type YPositionChildren = FilteredChildren;
pub type PositionChildren = daggy::walker::Chain<Graph, u32, XPositionChildren, YPositionChildren>;
pub type GraphicChildren = FilteredChildren;
pub type RecursiveWalk<F> = daggy::walker::Recursive<Graph, u32, F>;
pub type WouldCycle = daggy::WouldCycle<Edge>;
#[derive(Debug)]
pub struct UniqueWidgetState<State, Style> where
State: Any,
Style: Any,
{
pub state: State,
pub style: Style,
}
#[derive(Debug)]
pub struct Container {
pub maybe_state: Option<Box<Any>>,
pub kind: &'static str,
pub rect: Rect,
pub depth: Depth,
pub kid_area: widget::KidArea,
pub maybe_floating: Option<widget::Floating>,
pub crop_kids: bool,
pub maybe_x_scroll_state: Option<widget::scroll::StateX>,
pub maybe_y_scroll_state: Option<widget::scroll::StateY>,
pub instantiation_order_idx: usize,
}
#[derive(Debug)]
pub enum Node {
Widget(Container),
Placeholder,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Edge {
Position(Axis),
Depth,
Graphic,
}
pub const NUM_EDGE_VARIANTS: usize = 4;
type Dag = daggy::Dag<Node, Edge>;
#[derive(Debug)]
pub struct Graph {
dag: Dag,
index_map: IndexMap,
}
const NO_MATCHING_NODE_INDEX: &'static str = "No matching NodeIndex";
impl Container {
pub fn state_and_style<State, Style>(&self) -> Option<&UniqueWidgetState<State, Style>>
where State: Any + 'static,
Style: Any + 'static,
{
self.maybe_state.as_ref().and_then(|boxed_state| boxed_state.downcast_ref())
}
pub fn unique_widget_state<W>(&self) -> Option<&UniqueWidgetState<W::State, W::Style>>
where W: Widget,
W::State: Any + 'static,
W::Style: Any + 'static,
{
self.state_and_style::<W::State, W::Style>()
}
pub fn take_unique_widget_state<W>(&mut self)
-> Option<Box<UniqueWidgetState<W::State, W::Style>>>
where W: Widget,
W::State: Any + 'static,
W::Style: Any + 'static,
{
self.maybe_state.take().map(|any_state| {
any_state.downcast().ok()
.expect("Failed to downcast from `Box<Any>` to the required UniqueWidgetState")
})
}
pub fn take_widget_state<W>(&mut self) -> Option<widget::Cached<W>>
where W: Widget,
W::State: Any + 'static,
W::Style: Any + 'static,
{
if self.maybe_state.is_some() {
let boxed_unique_state = self.take_unique_widget_state::<W>().unwrap();
let unique_state: UniqueWidgetState<W::State, W::Style> = *boxed_unique_state;
let UniqueWidgetState { state, style } = unique_state;
Some(widget::Cached {
state: state,
style: style,
rect: self.rect,
depth: self.depth,
kid_area: self.kid_area,
maybe_floating: self.maybe_floating,
maybe_x_scroll_state: self.maybe_x_scroll_state,
maybe_y_scroll_state: self.maybe_y_scroll_state,
})
} else {
None
}
}
}
impl Node {
pub fn is_widget(&self) -> bool {
if let Node::Widget(_) = *self { true } else { false }
}
}
impl Graph {
pub fn new() -> Self {
Graph {
dag: Dag::new(),
index_map: IndexMap::new(),
}
}
pub fn with_node_capacity(n_nodes: usize) -> Self {
let n_edges = n_nodes * NUM_EDGE_VARIANTS;
Graph {
dag: Dag::with_capacity(n_nodes, n_edges),
index_map: IndexMap::with_capacity(n_nodes),
}
}
pub fn clear(&mut self) {
self.dag.clear()
}
pub fn node_count(&self) -> usize {
self.dag.node_count()
}
pub fn widget_count(&self) -> usize {
(0..self.node_count())
.filter(|&i| self[NodeIndex::new(i)].is_widget())
.count()
}
pub fn edge_count(&self) -> usize {
self.dag.edge_count()
}
pub fn node_capacity(&self) -> usize {
unimplemented!();
}
pub fn convert_idx<I, J>(&self, idx: I) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
J::from_idx(idx, &self.index_map)
}
pub fn node_index<I: GraphIndex>(&self, idx: I) -> Option<NodeIndex> {
self.convert_idx(idx)
}
pub fn widget_id<I: GraphIndex>(&self, idx: I) -> Option<widget::Id> {
self.convert_idx(idx)
}
pub fn widget_index<I: GraphIndex>(&self, idx: I) -> Option<widget::Index> {
self.widget_id(idx).map(|id| widget::Index::Public(id))
.or_else(|| self.node_index(idx).map(|idx| widget::Index::Internal(idx)))
}
fn add_node(&mut self, node: Node) -> NodeIndex {
self.dag.add_node(node)
}
fn set_edge<A, B>(&mut self, a: A, b: B, edge: Edge) -> Result<EdgeIndex, WouldCycle>
where A: GraphIndex,
B: GraphIndex,
{
let a = self.node_index(a).expect(NO_MATCHING_NODE_INDEX);
let b = self.node_index(b).expect(NO_MATCHING_NODE_INDEX);
let mut parents = self.parents(b);
let mut already_set = None;
while let Some((in_edge_idx, in_node_idx)) = parents.next(self) {
if edge == self[in_edge_idx] {
if in_node_idx == a {
already_set = Some(in_edge_idx);
} else {
self.remove_edge(in_edge_idx);
}
break;
}
}
match already_set {
Some(edge_idx) => Ok(edge_idx),
None => self.dag.add_edge(a, b, edge),
}
}
fn remove_edge(&mut self, idx: EdgeIndex) -> Option<Edge> {
self.dag.remove_edge(idx)
}
fn remove_parent_edge<I: GraphIndex>(&mut self, idx: I, edge: Edge) -> bool {
self.node_index(idx).map(|idx| {
if let Some((edge_idx, _)) = self.parents(idx).find(self, |g, e, _| g[e] == edge) {
self.remove_edge(edge_idx);
return true;
}
false
}).unwrap_or(false)
}
pub fn add_placeholder(&mut self) -> NodeIndex {
self.add_node(Node::Placeholder)
}
pub fn node<I: GraphIndex>(&self, idx: I) -> Option<&Node> {
self.node_index(idx).and_then(|idx| self.dag.node_weight(idx))
}
pub fn node_mut<I: GraphIndex>(&mut self, idx: I) -> Option<&mut Node> {
self.node_index(idx).and_then(move |idx| self.dag.node_weight_mut(idx))
}
pub fn edge(&self, idx: EdgeIndex) -> Option<&Edge> {
self.dag.edge_weight(idx)
}
pub fn edge_mut(&mut self, idx: EdgeIndex) -> Option<&mut Edge> {
self.dag.edge_weight_mut(idx)
}
pub fn edge_endpoints(&self, idx: EdgeIndex) -> Option<(NodeIndex, NodeIndex)> {
self.dag.edge_endpoints(idx)
}
pub fn widget<I: GraphIndex>(&self, idx: I) -> Option<&Container> {
self.node(idx).and_then(|node| match *node {
Node::Widget(ref container) => Some(container),
_ => None,
})
}
pub fn widget_mut<I: GraphIndex>(&mut self, idx: I) -> Option<&mut Container> {
self.node_mut(idx).and_then(|node| match *node {
Node::Widget(ref mut container) => Some(container),
_ => None,
})
}
pub fn parents<I: GraphIndex>(&self, child: I) -> Parents {
let idx = self.node_index(child).unwrap_or(NodeIndex::end());
self.dag.parents(idx)
}
pub fn recursive_walk<I, F>(&self, start: I, recursive_fn: F) -> RecursiveWalk<F>
where I: GraphIndex,
F: FnMut(&Self, NodeIndex) -> Option<(EdgeIndex, NodeIndex)>
{
let start = self.node_index(start).expect(NO_MATCHING_NODE_INDEX);
RecursiveWalk::new(start, recursive_fn)
}
pub fn edge_parent<I, J>(&self, idx: I, edge: Edge) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
self.parents(idx).find(self, |g, e, _| g[e] == edge).and_then(|(_, n)| self.convert_idx(n))
}
pub fn depth_parent<I, J>(&self, idx: I) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
self.edge_parent(idx, Edge::Depth)
}
pub fn x_position_parent<I, J>(&self, idx: I) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
self.edge_parent(idx, Edge::Position(Axis::X))
}
pub fn y_position_parent<I, J>(&self, idx: I) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
self.edge_parent(idx, Edge::Position(Axis::Y))
}
pub fn position_parents<I, J>(&self, idx: I) -> PositionParents<J>
where I: GraphIndex,
J: GraphIndex,
{
self.x_position_parent(idx).into_iter().chain(self.y_position_parent(idx))
}
pub fn graphic_parent<I, J>(&self, idx: I) -> Option<J>
where I: GraphIndex,
J: GraphIndex,
{
self.edge_parent(idx, Edge::Graphic)
}
pub fn depth_parent_recursion<I: GraphIndex>(&self, idx: I)
-> RecursiveWalk<fn(&Graph, NodeIndex) -> Option<IndexPair>>
{
fn depth_edge_parent(graph: &Graph, idx: NodeIndex) -> Option<IndexPair> {
graph.parents(idx).find(graph, |g, e, _| g[e] == Edge::Depth)
}
self.recursive_walk(idx, depth_edge_parent)
}
pub fn x_position_parent_recursion<I: GraphIndex>(&self, idx: I)
-> RecursiveWalk<fn(&Graph, NodeIndex) -> Option<IndexPair>>
{
fn x_position_edge_parent(graph: &Graph, idx: NodeIndex) -> Option<IndexPair> {
graph.parents(idx).find(graph, |g, e, _| g[e] == Edge::Position(Axis::X))
}
self.recursive_walk(idx, x_position_edge_parent)
}
pub fn y_position_parent_recursion<I: GraphIndex>(&self, idx: I)
-> RecursiveWalk<fn(&Graph, NodeIndex) -> Option<IndexPair>>
{
fn y_position_edge_parent(graph: &Graph, idx: NodeIndex) -> Option<IndexPair> {
graph.parents(idx).find(graph, |g, e, _| g[e] == Edge::Position(Axis::Y))
}
self.recursive_walk(idx, y_position_edge_parent)
}
pub fn graphic_parent_recursion<I: GraphIndex>(&self, idx: I)
-> RecursiveWalk<fn(&Graph, NodeIndex) -> Option<IndexPair>>
{
fn graphic_edge_parent(graph: &Graph, idx: NodeIndex) -> Option<IndexPair> {
graph.parents(idx).find(graph, |g, e, _| g[e] == Edge::Graphic)
}
self.recursive_walk(idx, graphic_edge_parent)
}
pub fn children<I: GraphIndex>(&self, parent: I) -> Children {
let idx = self.node_index(parent).unwrap_or(NodeIndex::end());
self.dag.children(idx)
}
pub fn depth_children<I: GraphIndex>(&self, idx: I) -> DepthChildren {
self.children(idx).filter(is_depth_edge)
}
pub fn x_position_children<I: GraphIndex>(&self, idx: I) -> XPositionChildren {
self.children(idx).filter(is_x_position_edge)
}
pub fn y_position_children<I: GraphIndex>(&self, idx: I) -> YPositionChildren {
self.children(idx).filter(is_y_position_edge)
}
pub fn position_children<I: GraphIndex>(&self, idx: I) -> PositionChildren {
self.x_position_children(idx).chain(self.y_position_children(idx))
}
pub fn graphic_children<I: GraphIndex>(&self, idx: I) -> GraphicChildren {
self.children(idx).filter(is_graphic_edge)
}
pub fn does_edge_exist<P, C, F>(&self, parent: P, child: C, is_edge: F) -> bool
where P: GraphIndex,
C: GraphIndex,
F: Fn(Edge) -> bool,
{
self.node_index(parent).map(|parent| {
self.parents(child).any(self, |g, e, n| n == parent && is_edge(g[e]))
}).unwrap_or(false)
}
pub fn does_depth_edge_exist<P, C>(&self, parent: P, child: C) -> bool
where P: GraphIndex,
C: GraphIndex,
{
self.does_edge_exist(parent, child, |e| e == Edge::Depth)
}
pub fn does_position_edge_exist<P, C>(&self, parent: P, child: C) -> bool
where P: GraphIndex,
C: GraphIndex,
{
let is_edge = |e| e == Edge::Position(Axis::X) || e == Edge::Position(Axis::Y);
self.does_edge_exist(parent, child, is_edge)
}
pub fn does_graphic_edge_exist<P, C>(&self, parent: P, child: C) -> bool
where P: GraphIndex,
C: GraphIndex,
{
self.does_edge_exist(parent, child, |e| e == Edge::Graphic)
}
pub fn does_recursive_edge_exist<P, C, F>(&self, parent: P, child: C, is_edge: F) -> bool
where P: GraphIndex,
C: GraphIndex,
F: Fn(Edge) -> bool,
{
self.node_index(parent).map(|parent| {
self.recursive_walk(child, |g, n| g.parents(n).find(g, |g, e, _| is_edge(g[e])))
.any(self, |_, _, n| n == parent)
}).unwrap_or(false)
}
pub fn does_recursive_depth_edge_exist<P, C>(&self, parent: P, child: C) -> bool
where P: GraphIndex,
C: GraphIndex,
{
self.does_recursive_edge_exist(parent, child, |e| e == Edge::Depth)
}
pub fn does_recursive_graphic_edge_exist<P, C>(&self, parent: P, child: C) -> bool
where P: GraphIndex,
C: GraphIndex,
{
self.does_recursive_edge_exist(parent, child, |e| e == Edge::Graphic)
}
pub fn pre_update_cache(&mut self,
root: NodeIndex,
widget: widget::PreUpdateCache,
instantiation_order_idx: usize)
{
let widget::PreUpdateCache {
kind, idx, maybe_parent_idx, maybe_x_positioned_relatively_idx,
maybe_y_positioned_relatively_idx, rect, depth, kid_area, maybe_floating,
crop_kids, maybe_x_scroll_state, maybe_y_scroll_state, maybe_graphics_for,
} = widget;
let new_container = || Container {
maybe_state: None,
kind: kind,
rect: rect,
depth: depth,
kid_area: kid_area,
maybe_floating: maybe_floating,
crop_kids: crop_kids,
maybe_x_scroll_state: maybe_x_scroll_state,
maybe_y_scroll_state: maybe_y_scroll_state,
instantiation_order_idx: instantiation_order_idx,
};
let maybe_parent_idx = |graph: &mut Self| match maybe_parent_idx {
Some(parent_idx) => match graph.node_index(parent_idx) {
Some(idx) => Some(idx),
None => {
let parent_node_idx = graph.add_placeholder();
if let widget::Index::Public(parent_widget_id) = parent_idx {
graph.index_map.insert(parent_widget_id, parent_node_idx);
}
Some(parent_node_idx)
},
},
None => graph.node_index(idx)
.and_then(|idx| if idx == root { None } else { Some(root) }),
};
if let Some(node_idx) = self.node_index(idx) {
if let Some(parent_idx) = maybe_parent_idx(self) {
self.set_edge(parent_idx, node_idx, Edge::Depth).unwrap();
}
match &mut self.dag[node_idx] {
node @ &mut Node::Placeholder => *node = Node::Widget(new_container()),
&mut Node::Widget(ref mut container) => {
if container.kind != kind && container.kind != "EMPTY" {
panic!("A widget of a different kind already exists at the given idx \
({:?}). You tried to insert a {:?}, however the existing \
widget is a {:?}. Check your `WidgetId`s for errors.",
idx, &kind, container.kind);
}
container.kind = kind;
container.rect = rect;
container.depth = depth;
container.kid_area = kid_area;
container.maybe_floating = maybe_floating;
container.crop_kids = crop_kids;
container.maybe_x_scroll_state = maybe_x_scroll_state;
container.maybe_y_scroll_state = maybe_y_scroll_state;
container.instantiation_order_idx = instantiation_order_idx;
},
}
} else if let Some(widget_id) = self.widget_id(idx) {
let node_idx = self.add_node(Node::Widget(new_container()));
self.index_map.insert(widget_id, node_idx);
if let Some(parent_idx) = maybe_parent_idx(self) {
self.set_edge(parent_idx, node_idx, Edge::Depth).unwrap();
}
}
if let Some(relative_idx) = maybe_x_positioned_relatively_idx {
self.set_edge(relative_idx, idx, Edge::Position(Axis::X)).unwrap();
} else {
self.remove_parent_edge(idx, Edge::Position(Axis::X));
}
if let Some(relative_idx) = maybe_y_positioned_relatively_idx {
self.set_edge(relative_idx, idx, Edge::Position(Axis::Y)).unwrap();
} else {
self.remove_parent_edge(idx, Edge::Position(Axis::Y));
}
if let Some(graphic_parent_idx) = maybe_graphics_for {
self.set_edge(graphic_parent_idx, idx, Edge::Graphic).unwrap();
} else {
self.remove_parent_edge(idx, Edge::Graphic);
}
}
pub fn post_update_cache<W>(&mut self, widget: widget::PostUpdateCache<W>)
where W: Widget,
W::State: 'static,
W::Style: 'static,
{
let widget::PostUpdateCache { idx, state, style, .. } = widget;
if let Some(ref mut container) = self.widget_mut(idx) {
let unique_state: UniqueWidgetState<W::State, W::Style> = UniqueWidgetState {
state: state,
style: style,
};
container.maybe_state = Some(Box::new(unique_state));
}
}
}
fn is_depth_edge(g: &Graph, e: EdgeIndex, _: NodeIndex) -> bool {
g[e] == Edge::Depth
}
fn is_x_position_edge(g: &Graph, e: EdgeIndex, _: NodeIndex) -> bool {
g[e] == Edge::Position(Axis::X)
}
fn is_y_position_edge(g: &Graph, e: EdgeIndex, _: NodeIndex) -> bool {
g[e] == Edge::Position(Axis::Y)
}
fn is_graphic_edge(g: &Graph, e: EdgeIndex, _: NodeIndex) -> bool {
g[e] == Edge::Graphic
}
impl Walker<Graph> for Children {
type Index = u32;
#[inline]
fn next(&mut self, graph: &Graph) -> Option<(EdgeIndex, NodeIndex)> {
self.next(&graph.dag)
}
}
impl Walker<Graph> for Parents {
type Index = u32;
#[inline]
fn next(&mut self, graph: &Graph) -> Option<(EdgeIndex, NodeIndex)> {
self.next(&graph.dag)
}
}
impl<I: GraphIndex> ::std::ops::Index<I> for Graph {
type Output = Node;
fn index<'a>(&'a self, idx: I) -> &'a Node {
self.node(idx).unwrap()
}
}
impl<I: GraphIndex> ::std::ops::IndexMut<I> for Graph {
fn index_mut<'a>(&'a mut self, idx: I) -> &'a mut Node {
self.node_mut(idx).unwrap()
}
}
impl Index<EdgeIndex> for Graph {
type Output = Edge;
fn index<'a>(&'a self, idx: EdgeIndex) -> &'a Edge {
self.edge(idx).unwrap()
}
}
impl IndexMut<EdgeIndex> for Graph {
fn index_mut<'a>(&'a mut self, idx: EdgeIndex) -> &'a mut Edge {
self.edge_mut(idx).unwrap()
}
}