1- use std:: ops:: { AddAssign , Deref } ;
2-
31macro_rules! declare_types {
42 ( $( <$lt: lifetime>) ?
53 $( derive( $( $Der: ident) ,* ) , ) ?
@@ -51,7 +49,18 @@ macro_rules! declare_types {
5149#[ derive( Debug , Copy , Clone ) ]
5250pub struct ModifierSet < S > ( S ) ;
5351
54- impl < S : Deref < Target = str > > ModifierSet < S > {
52+ impl < S : Default > Default for ModifierSet < S > {
53+ /// Construct the default modifier set.
54+ ///
55+ /// This is typically the empty set,
56+ /// though the remark from [`Self::new_unchecked`] applies
57+ /// since `S::default()` could technically be anything.
58+ fn default ( ) -> Self {
59+ Self ( S :: default ( ) )
60+ }
61+ }
62+
63+ impl < S : std:: ops:: Deref < Target = str > > ModifierSet < S > {
5564 /// Convert the underlying string to a slice.
5665 pub fn as_deref ( & self ) -> ModifierSet < & str > {
5766 ModifierSet ( & self . 0 )
@@ -68,14 +77,6 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
6877 Self ( s)
6978 }
7079
71- /// Construct an empty modifier set.
72- pub fn empty ( ) -> Self
73- where
74- S : Default ,
75- {
76- Self ( S :: default ( ) )
77- }
78-
7980 /// Whether `self` is empty.
8081 pub fn is_empty ( & self ) -> bool {
8182 self . 0 . is_empty ( )
@@ -88,7 +89,7 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
8889 /// `modifier` is not empty and doesn't contain the character `.`.
8990 pub fn add_unchecked ( & mut self , m : & str )
9091 where
91- S : for < ' a > AddAssign < & ' a str > ,
92+ S : for < ' a > std :: ops :: AddAssign < & ' a str > ,
9293 {
9394 if !self . 0 . is_empty ( ) {
9495 self . 0 += "." ;
@@ -136,8 +137,8 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
136137 total += 1 ;
137138 }
138139
139- let score = ( matching, core :: cmp:: Reverse ( total) ) ;
140- if best_score. map_or ( true , |b| score > b) {
140+ let score = ( matching, std :: cmp:: Reverse ( total) ) ;
141+ if best_score. is_none_or ( |b| score > b) {
141142 best = Some ( candidate. 1 ) ;
142143 best_score = Some ( score) ;
143144 }
@@ -146,3 +147,10 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
146147 best
147148 }
148149}
150+
151+ impl < ' a > ModifierSet < & ' a str > {
152+ /// Iterate over the list of modifiers with the original lifetime.
153+ pub fn to_iter ( self ) -> impl Iterator < Item = & ' a str > {
154+ self . 0 . split ( '.' ) . filter ( |s| !s. is_empty ( ) )
155+ }
156+ }
0 commit comments