1 2 use std::ops::{Deref, Index, IndexMut}; 3 4 use graph::Graph; 5 use super::Frozen; 6 use graph::{IndexType, GraphIndex}; 7 use { 8 Direction, 9 EdgeType, 10 }; 11 use visit::{Data, IntoNodeIdentifiers, GraphProp, NodeIndexable, IntoNeighborsDirected}; 12 use visit::{IntoNeighbors, IntoNodeReferences, IntoEdgeReferences, Visitable}; 13 use visit::{NodeCompactIndexable, GetAdjacencyMatrix, NodeCount, IntoEdges, IntoEdgesDirected}; 14 use data::{DataMap, DataMapMut}; 15 16 17 impl<'a, G> Frozen<'a, G> { 18 /// Create a new `Frozen` from a mutable reference to a graph. new(gr: &'a mut G) -> Self19 pub fn new(gr: &'a mut G) -> Self { 20 Frozen(gr) 21 } 22 } 23 24 /// Deref allows transparent access to all shared reference (read-only) 25 /// functionality in the underlying graph. 26 impl<'a, G> Deref for Frozen<'a, G> { 27 type Target = G; deref(&self) -> &G28 fn deref(&self) -> &G { self.0 } 29 } 30 31 impl<'a, G, I> Index<I> for Frozen<'a, G> 32 where G: Index<I> 33 { 34 type Output = G::Output; index(&self, i: I) -> &G::Output35 fn index(&self, i: I) -> &G::Output { self.0.index(i) } 36 } 37 38 impl<'a, G, I> IndexMut<I> for Frozen<'a, G> 39 where G: IndexMut<I> 40 { index_mut(&mut self, i: I) -> &mut G::Output41 fn index_mut(&mut self, i: I) -> &mut G::Output { self.0.index_mut(i) } 42 } 43 44 impl<'a, N, E, Ty, Ix> Frozen<'a, Graph<N, E, Ty, Ix>> 45 where Ty: EdgeType, 46 Ix: IndexType, 47 { 48 /// Index the `Graph` by two indices, any combination of 49 /// node or edge indices is fine. 50 /// 51 /// **Panics** if the indices are equal or if they are out of bounds. index_twice_mut<T, U>(&mut self, i: T, j: U) -> (&mut <Graph<N, E, Ty, Ix> as Index<T>>::Output, &mut <Graph<N, E, Ty, Ix> as Index<U>>::Output) where Graph<N, E, Ty, Ix>: IndexMut<T> + IndexMut<U>, T: GraphIndex, U: GraphIndex,52 pub fn index_twice_mut<T, U>(&mut self, i: T, j: U) 53 -> (&mut <Graph<N, E, Ty, Ix> as Index<T>>::Output, 54 &mut <Graph<N, E, Ty, Ix> as Index<U>>::Output) 55 where Graph<N, E, Ty, Ix>: IndexMut<T> + IndexMut<U>, 56 T: GraphIndex, 57 U: GraphIndex, 58 { 59 self.0.index_twice_mut(i, j) 60 } 61 } 62 63 macro_rules! access0 { 64 ($e:expr) => ($e.0); 65 } 66 67 Data!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 68 DataMap!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 69 DataMapMut!{delegate_impl [['a, G], G, Frozen<'a, G>, access0]} 70 GetAdjacencyMatrix!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 71 IntoEdgeReferences!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 72 IntoEdges!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 73 IntoEdgesDirected!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 74 IntoNeighbors!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 75 IntoNeighborsDirected!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 76 IntoNodeIdentifiers!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 77 IntoNodeReferences!{delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]} 78 NodeCompactIndexable!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 79 NodeCount!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 80 NodeIndexable!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 81 GraphProp!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 82 Visitable!{delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]} 83 84 85 86