@@ -5,9 +5,12 @@ use core::{
55 slice:: Iter ,
66} ;
77
8- use alloc:: { string :: String , vec:: Vec } ;
8+ use alloc:: vec:: Vec ;
99
10- use crate :: { Context , Node , Property } ;
10+ use crate :: {
11+ Context , Node ,
12+ node:: gerneric:: { NodeMutGen , NodeRefGen } ,
13+ } ;
1114
1215#[ derive( Clone , Debug ) ]
1316pub enum NodeRef < ' a > {
@@ -18,49 +21,6 @@ impl<'a> NodeRef<'a> {
1821 pub fn new ( node : & ' a Node , ctx : Context < ' a > ) -> Self {
1922 Self :: Gerneric ( NodeRefGen { node, ctx } )
2023 }
21-
22- fn op ( & ' a self ) -> RefOp < ' a > {
23- RefOp {
24- ctx : & self . ctx ,
25- node : self . node ,
26- }
27- }
28-
29- pub fn path ( & self ) -> String {
30- self . op ( ) . path ( )
31- }
32-
33- pub fn path_eq ( & self , path : & str ) -> bool {
34- self . op ( ) . ref_path_eq ( path)
35- }
36-
37- pub fn path_eq_fuzzy ( & self , path : & str ) -> bool {
38- self . op ( ) . ref_path_eq_fuzzy ( path)
39- }
40- }
41-
42- #[ derive( Clone ) ]
43- pub struct NodeRefGen < ' a > {
44- pub node : & ' a Node ,
45- pub ctx : Context < ' a > ,
46- }
47-
48- impl < ' a > NodeRefGen < ' a > {
49- pub fn find_property ( & self , name : & str ) -> Option < & ' a Property > {
50- self . node . properties . get ( name)
51- }
52-
53- pub fn properties ( & self ) -> impl Iterator < Item = & ' a Property > {
54- self . node . properties . values ( )
55- }
56- }
57-
58- impl Deref for NodeRefGen < ' _ > {
59- type Target = Node ;
60-
61- fn deref ( & self ) -> & Self :: Target {
62- self . node
63- }
6424}
6525
6626impl < ' a > Deref for NodeRef < ' a > {
@@ -73,11 +33,6 @@ impl<'a> Deref for NodeRef<'a> {
7333 }
7434}
7535
76- pub struct NodeMutGen < ' a > {
77- pub node : & ' a mut Node ,
78- pub ctx : Context < ' a > ,
79- }
80-
8136#[ derive( Debug ) ]
8237pub enum NodeMut < ' a > {
8338 Gerneric ( NodeMutGen < ' a > ) ,
@@ -87,25 +42,6 @@ impl<'a> NodeMut<'a> {
8742 pub fn new ( node : & ' a mut Node , ctx : Context < ' a > ) -> Self {
8843 Self :: Gerneric ( NodeMutGen { node, ctx } )
8944 }
90-
91- fn op ( & ' a self ) -> RefOp < ' a > {
92- RefOp {
93- ctx : & self . ctx ,
94- node : self . node ,
95- }
96- }
97-
98- pub fn path ( & self ) -> String {
99- self . op ( ) . path ( )
100- }
101-
102- pub fn path_eq ( & self , path : & str ) -> bool {
103- self . op ( ) . ref_path_eq ( path)
104- }
105-
106- pub fn path_eq_fuzzy ( & self , path : & str ) -> bool {
107- self . op ( ) . ref_path_eq_fuzzy ( path)
108- }
10945}
11046
11147impl < ' a > Deref for NodeMut < ' a > {
@@ -251,72 +187,3 @@ impl<'a> Iterator for NodeIterMut<'a> {
251187 self . next ( )
252188 }
253189}
254-
255- impl Debug for NodeRefGen < ' _ > {
256- fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
257- write ! ( f, "NodeRefGen {{ name: {} }}" , self . node. name( ) )
258- }
259- }
260-
261- impl Debug for NodeMutGen < ' _ > {
262- fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
263- write ! ( f, "NodeMutGen {{ name: {} }}" , self . node. name( ) )
264- }
265- }
266-
267- struct RefOp < ' a > {
268- ctx : & ' a Context < ' a > ,
269- node : & ' a Node ,
270- }
271-
272- impl < ' a > RefOp < ' a > {
273- fn path ( & self ) -> String {
274- self . ctx . current_path ( ) + "/" + self . node . name ( )
275- }
276-
277- fn ref_path_eq ( & self , path : & str ) -> bool {
278- self . path ( ) == path
279- }
280-
281- fn ref_path_eq_fuzzy ( & self , path : & str ) -> bool {
282- let mut want = path. trim_matches ( '/' ) . split ( "/" ) ;
283- let got_path = self . path ( ) ;
284- let mut got = got_path. trim_matches ( '/' ) . split ( "/" ) ;
285- let got_count = got. clone ( ) . count ( ) ;
286- let mut current = 0 ;
287-
288- loop {
289- let w = want. next ( ) ;
290- let g = got. next ( ) ;
291- let is_last = current + 1 == got_count;
292-
293- match ( w, g) {
294- ( Some ( w) , Some ( g) ) => {
295- if w != g && !is_last {
296- return false ;
297- }
298-
299- let name = g. split ( '@' ) . next ( ) . unwrap_or ( g) ;
300- let addr = g. split ( '@' ) . nth ( 1 ) ;
301-
302- let want_name = w. split ( '@' ) . next ( ) . unwrap_or ( w) ;
303- let want_addr = w. split ( '@' ) . nth ( 1 ) ;
304-
305- let res = match ( addr, want_addr) {
306- ( Some ( a) , Some ( wa) ) => name == want_name && a == wa,
307- ( Some ( _) , None ) => name == want_name,
308- ( None , Some ( _) ) => false ,
309- ( None , None ) => name == want_name,
310- } ;
311- if !res {
312- return false ;
313- }
314- }
315- ( None , _) => break ,
316- _ => return false ,
317- }
318- current += 1 ;
319- }
320- true
321- }
322- }
0 commit comments