1use std::ops::{Deref, Index, IndexMut};
2
3use super::Frozen;
4use crate::data::{DataMap, DataMapMut};
5use crate::graph::Graph;
6use crate::graph::{GraphIndex, IndexType};
7use crate::visit::{
8 Data, EdgeCount, EdgeIndexable, GetAdjacencyMatrix, GraphBase, GraphProp, IntoEdges,
9 IntoEdgesDirected, IntoNeighborsDirected, IntoNodeIdentifiers, NodeCompactIndexable, NodeCount,
10 NodeIndexable,
11};
12use crate::visit::{IntoEdgeReferences, IntoNeighbors, IntoNodeReferences, Visitable};
13use crate::{Direction, EdgeType};
14
15impl<'a, G> Frozen<'a, G> {
16 pub fn new(gr: &'a mut G) -> Self {
18 Frozen(gr)
19 }
20}
21
22impl<G> Deref for Frozen<'_, G> {
25 type Target = G;
26 fn deref(&self) -> &G {
27 self.0
28 }
29}
30
31impl<G, I> Index<I> for Frozen<'_, G>
32where
33 G: Index<I>,
34{
35 type Output = G::Output;
36 fn index(&self, i: I) -> &G::Output {
37 self.0.index(i)
38 }
39}
40
41impl<G, I> IndexMut<I> for Frozen<'_, G>
42where
43 G: IndexMut<I>,
44{
45 fn index_mut(&mut self, i: I) -> &mut G::Output {
46 self.0.index_mut(i)
47 }
48}
49
50impl<N, E, Ty, Ix> Frozen<'_, Graph<N, E, Ty, Ix>>
51where
52 Ty: EdgeType,
53 Ix: IndexType,
54{
55 #[allow(clippy::type_complexity)]
56 pub fn index_twice_mut<T, U>(
61 &mut self,
62 i: T,
63 j: U,
64 ) -> (
65 &mut <Graph<N, E, Ty, Ix> as Index<T>>::Output,
66 &mut <Graph<N, E, Ty, Ix> as Index<U>>::Output,
67 )
68 where
69 Graph<N, E, Ty, Ix>: IndexMut<T> + IndexMut<U>,
70 T: GraphIndex,
71 U: GraphIndex,
72 {
73 self.0.index_twice_mut(i, j)
74 }
75}
76
77macro_rules! access0 {
78 ($e:expr) => {
79 $e.0
80 };
81}
82
83impl<G> GraphBase for Frozen<'_, G>
84where
85 G: GraphBase,
86{
87 type NodeId = G::NodeId;
88 type EdgeId = G::EdgeId;
89}
90
91Data! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
92DataMap! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
93DataMapMut! {delegate_impl [['a, G], G, Frozen<'a, G>, access0]}
94GetAdjacencyMatrix! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
95IntoEdgeReferences! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
96IntoEdges! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
97IntoEdgesDirected! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
98IntoNeighbors! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
99IntoNeighborsDirected! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
100IntoNodeIdentifiers! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
101IntoNodeReferences! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
102NodeCompactIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
103NodeCount! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
104NodeIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
105EdgeCount! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
106EdgeIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
107GraphProp! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
108Visitable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}