1use core::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 #[track_caller]
61 pub fn index_twice_mut<T, U>(
62 &mut self,
63 i: T,
64 j: U,
65 ) -> (
66 &mut <Graph<N, E, Ty, Ix> as Index<T>>::Output,
67 &mut <Graph<N, E, Ty, Ix> as Index<U>>::Output,
68 )
69 where
70 Graph<N, E, Ty, Ix>: IndexMut<T> + IndexMut<U>,
71 T: GraphIndex,
72 U: GraphIndex,
73 {
74 self.0.index_twice_mut(i, j)
75 }
76}
77
78macro_rules! access0 {
79 ($e:expr) => {
80 $e.0
81 };
82}
83
84impl<G> GraphBase for Frozen<'_, G>
85where
86 G: GraphBase,
87{
88 type NodeId = G::NodeId;
89 type EdgeId = G::EdgeId;
90}
91
92Data! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
93DataMap! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
94DataMapMut! {delegate_impl [['a, G], G, Frozen<'a, G>, access0]}
95GetAdjacencyMatrix! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
96IntoEdgeReferences! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
97IntoEdges! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
98IntoEdgesDirected! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
99IntoNeighbors! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
100IntoNeighborsDirected! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
101IntoNodeIdentifiers! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
102IntoNodeReferences! {delegate_impl [['a, 'b, G], G, &'b Frozen<'a, G>, deref_twice]}
103NodeCompactIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
104NodeCount! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
105NodeIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
106EdgeCount! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
107EdgeIndexable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
108GraphProp! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}
109Visitable! {delegate_impl [['a, G], G, Frozen<'a, G>, deref_twice]}