fera_graph/props/
delegate.rs1use prelude::*;
6
7use std::ops::{Index, IndexMut};
8
9pub struct DelegateVertexProp<G: WithVertexProp<T>, T>(DefaultVertexPropMut<G, T>);
11
12impl<G: WithVertexProp<T>, T> Index<Vertex<G>> for DelegateVertexProp<G, T> {
13 type Output = T;
14
15 #[inline]
16 fn index(&self, v: Vertex<G>) -> &Self::Output {
17 self.0.index(v)
18 }
19}
20
21impl<G: WithVertexProp<T>, T> IndexMut<Vertex<G>> for DelegateVertexProp<G, T> {
22 #[inline]
23 fn index_mut(&mut self, v: Vertex<G>) -> &mut Self::Output {
24 self.0.index_mut(v)
25 }
26}
27
28impl<G, D, T> VertexPropMutNew<G, T> for DelegateVertexProp<D, T>
29where
30 G: WithVertex<Vertex = Vertex<D>, OptionVertex = OptionVertex<D>> + AsRef<D>,
31 D: WithVertexProp<T>,
32{
33 fn new_vertex_prop(g: &G, value: T) -> Self
34 where
35 T: Clone,
36 {
37 DelegateVertexProp(g.as_ref().vertex_prop(value))
38 }
39}
40
41pub struct DelegateEdgeProp<G: WithEdgeProp<T>, T>(DefaultEdgePropMut<G, T>);
43
44impl<G: WithEdgeProp<T>, T> Index<Edge<G>> for DelegateEdgeProp<G, T> {
45 type Output = T;
46
47 #[inline]
48 fn index(&self, v: Edge<G>) -> &Self::Output {
49 self.0.index(v)
50 }
51}
52
53impl<G: WithEdgeProp<T>, T> IndexMut<Edge<G>> for DelegateEdgeProp<G, T> {
54 #[inline]
55 fn index_mut(&mut self, v: Edge<G>) -> &mut Self::Output {
56 self.0.index_mut(v)
57 }
58}
59
60impl<G, D, T> EdgePropMutNew<G, T> for DelegateEdgeProp<D, T>
61where
62 G: WithEdge<Edge = Edge<D>, OptionEdge = OptionEdge<D>> + AsRef<D>,
63 D: WithEdgeProp<T>,
64{
65 fn new_edge_prop(g: &G, value: T) -> Self
66 where
67 T: Clone,
68 {
69 DelegateEdgeProp(g.as_ref().edge_prop(value))
70 }
71}