@@ -36,16 +36,20 @@ pub trait AsNode<'a, P: ParserWithMode<'a>> {
36
36
fn as_node ( & self ) -> Node < ' a , P > ;
37
37
}
38
38
39
+ /// A node name that can searched with.
39
40
#[ derive( Debug , Clone , Copy ) ]
40
41
pub enum SearchableNodeName < ' a > {
42
+ /// Node name without the unit address
41
43
Base ( & ' a str ) ,
44
+ /// Node name with the unit address
42
45
WithUnitAddress ( NodeName < ' a > ) ,
43
46
}
44
47
45
48
/// Convert from a type that can potentially represent a node name that is able
46
49
/// to be searched for during lookup operations.
47
50
///
48
- /// Currently, two type impls are defined:
51
+ /// Currently, two type impls are defined on types other than
52
+ /// [`SearchableNodeName`]:
49
53
/// 1. [`NodeName`]: corresponds directly to a
50
54
/// [`SearchableNodeName::WithUnitAddress`].
51
55
/// 2. [`&str`]: attempts to parse the `str` as `name@unit-address`,
@@ -56,6 +60,13 @@ pub trait IntoSearchableNodeName<'a>: Sized + crate::sealed::Sealed {
56
60
fn into_searchable_node_name ( self ) -> SearchableNodeName < ' a > ;
57
61
}
58
62
63
+ impl crate :: sealed:: Sealed for SearchableNodeName < ' _ > { }
64
+ impl < ' a > IntoSearchableNodeName < ' a > for SearchableNodeName < ' a > {
65
+ fn into_searchable_node_name ( self ) -> SearchableNodeName < ' a > {
66
+ self
67
+ }
68
+ }
69
+
59
70
impl crate :: sealed:: Sealed for NodeName < ' _ > { }
60
71
impl < ' a > IntoSearchableNodeName < ' a > for NodeName < ' a > {
61
72
fn into_searchable_node_name ( self ) -> SearchableNodeName < ' a > {
@@ -75,9 +86,12 @@ impl<'a> IntoSearchableNodeName<'a> for &'a str {
75
86
}
76
87
}
77
88
89
+ /// A node name, split into its component parts.
78
90
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
79
91
pub struct NodeName < ' a > {
92
+ /// Node name.
80
93
pub name : & ' a str ,
94
+ /// Optional unit address specified after the `@`.
81
95
pub unit_address : Option < & ' a str > ,
82
96
}
83
97
@@ -108,7 +122,7 @@ pub struct Node<'a, P: ParserWithMode<'a>> {
108
122
impl < ' a , P : ParserWithMode < ' a > > Node < ' a , P > {
109
123
/// Change the type of this node's [`PanicMode`] to [`NoPanic`].
110
124
#[ inline( always) ]
111
- pub ( crate ) fn fallible ( self ) -> FallibleNode < ' a , P > {
125
+ pub fn fallible ( self ) -> FallibleNode < ' a , P > {
112
126
self . alt ( )
113
127
}
114
128
@@ -377,6 +391,8 @@ impl<Granularity> RawNode<Granularity> {
377
391
}
378
392
}
379
393
394
+ /// Allows for searching and iterating over all of the properties of a given
395
+ /// [`Node`].
380
396
pub struct NodeProperties < ' a , P : ParserWithMode < ' a > = ( AlignedParser < ' a > , Panic ) > {
381
397
data : & ' a [ <P as Parser < ' a > >:: Granularity ] ,
382
398
strings : StringsBlock < ' a > ,
@@ -394,6 +410,7 @@ impl<'a, P: ParserWithMode<'a>> NodeProperties<'a, P> {
394
410
}
395
411
}
396
412
413
+ /// Create an iterator over the properties in the [`Node`].
397
414
#[ inline( always) ]
398
415
pub fn iter ( self ) -> NodePropertiesIter < ' a , P > {
399
416
NodePropertiesIter { properties : self . alt ( ) , _mode : core:: marker:: PhantomData }
@@ -426,6 +443,7 @@ impl<'a, P: ParserWithMode<'a>> NodeProperties<'a, P> {
426
443
} ) )
427
444
}
428
445
446
+ /// Attempt to find a property with the provided name.
429
447
#[ inline]
430
448
#[ track_caller]
431
449
pub fn find ( & self , name : & str ) -> P :: Output < Option < NodeProperty < ' a > > > {
@@ -465,6 +483,7 @@ impl<'a, P: ParserWithMode<'a>> IntoIterator for NodeProperties<'a, P> {
465
483
}
466
484
}
467
485
486
+ /// See [`NodeProperties::iter`].
468
487
#[ derive( Clone ) ]
469
488
pub struct NodePropertiesIter < ' a , P : ParserWithMode < ' a > = ( AlignedParser < ' a > , Panic ) > {
470
489
properties : NodeProperties < ' a , ( P :: Parser , NoPanic ) > ,
@@ -486,10 +505,13 @@ impl<'a, P: ParserWithMode<'a>> Iterator for NodePropertiesIter<'a, P> {
486
505
}
487
506
}
488
507
508
+ /// Generic node property.
489
509
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
490
510
pub struct NodeProperty < ' a > {
491
- name : & ' a str ,
492
- value : & ' a [ u8 ] ,
511
+ /// Property name.
512
+ pub name : & ' a str ,
513
+ /// Raw property value.
514
+ pub value : & ' a [ u8 ] ,
493
515
}
494
516
495
517
impl < ' a > NodeProperty < ' a > {
@@ -498,22 +520,15 @@ impl<'a> NodeProperty<'a> {
498
520
Self { name, value }
499
521
}
500
522
501
- #[ inline( always) ]
502
- pub fn name ( & self ) -> & ' a str {
503
- self . name
504
- }
505
-
506
- #[ inline( always) ]
507
- pub fn value ( & self ) -> & ' a [ u8 ] {
508
- self . value
509
- }
510
-
523
+ /// Attempt to convert this property's value to the specified
524
+ /// [`PropertyValue`] type.
511
525
#[ inline( always) ]
512
526
pub fn as_value < V : PropertyValue < ' a > > ( & self ) -> Result < V , InvalidPropertyValue > {
513
527
V :: parse ( self . value )
514
528
}
515
529
}
516
530
531
+ /// Allows for searching and iterating over the children of a given [`Node`].
517
532
pub struct NodeChildren < ' a , P : ParserWithMode < ' a > = ( AlignedParser < ' a > , Panic ) > {
518
533
data : & ' a [ <P as Parser < ' a > >:: Granularity ] ,
519
534
parent : & ' a RawNode < <P as Parser < ' a > >:: Granularity > ,
@@ -523,6 +538,7 @@ pub struct NodeChildren<'a, P: ParserWithMode<'a> = (AlignedParser<'a>, Panic)>
523
538
}
524
539
525
540
impl < ' a , P : ParserWithMode < ' a > > NodeChildren < ' a , P > {
541
+ /// Create an iterator over the [`Node`]'s children.
526
542
#[ inline( always) ]
527
543
pub fn iter ( & self ) -> NodeChildrenIter < ' a , P > {
528
544
NodeChildrenIter {
@@ -559,6 +575,10 @@ impl<'a, P: ParserWithMode<'a>> NodeChildren<'a, P> {
559
575
} )
560
576
}
561
577
578
+ /// Attempt to find the first child matching the provided name, see
579
+ /// [`IntoSearchableNodeName`] for more details. If the name lacks a unit
580
+ /// address, unit addresses on the children will be ignored when checking if
581
+ /// the name matches.
562
582
#[ inline]
563
583
#[ track_caller]
564
584
pub fn find < ' n , N > ( & self , name : N ) -> P :: Output < Option < Node < ' a , P > > >
@@ -609,6 +629,7 @@ impl<'a, P: ParserWithMode<'a>> IntoIterator for NodeChildren<'a, P> {
609
629
}
610
630
}
611
631
632
+ /// See [`NodeChildren::iter`].
612
633
#[ derive( Clone ) ]
613
634
pub struct NodeChildrenIter < ' a , P : ParserWithMode < ' a > = ( AlignedParser < ' a > , Panic ) > {
614
635
children : NodeChildren < ' a , ( P :: Parser , NoPanic ) > ,
0 commit comments