@@ -96,6 +96,11 @@ impl Comment {
9696 } ,
9797 )
9898 }
99+
100+ /// Check if this comment is a custom tag.
101+ pub fn is_custom ( & self ) -> bool {
102+ matches ! ( self . tag, CommentTag :: Custom ( _) )
103+ }
99104}
100105
101106/// The collection of natspec [Comment] items.
@@ -157,18 +162,18 @@ impl From<Vec<DocCommentTag>> for Comments {
157162pub struct CommentsRef < ' a > ( Vec < & ' a Comment > ) ;
158163
159164impl < ' a > CommentsRef < ' a > {
160- /// Filter a collection of comments and return only those that match a provided tag
165+ /// Filter a collection of comments and return only those that match a provided tag.
161166 pub fn include_tag ( & self , tag : CommentTag ) -> Self {
162167 self . include_tags ( & [ tag] )
163168 }
164169
165- /// Filter a collection of comments and return only those that match provided tags
170+ /// Filter a collection of comments and return only those that match provided tags.
166171 pub fn include_tags ( & self , tags : & [ CommentTag ] ) -> Self {
167172 // Cloning only references here
168173 CommentsRef ( self . iter ( ) . cloned ( ) . filter ( |c| tags. contains ( & c. tag ) ) . collect ( ) )
169174 }
170175
171- /// Filter a collection of comments and return only those that do not match provided tags
176+ /// Filter a collection of comments and return only those that do not match provided tags.
172177 pub fn exclude_tags ( & self , tags : & [ CommentTag ] ) -> Self {
173178 // Cloning only references here
174179 CommentsRef ( self . iter ( ) . cloned ( ) . filter ( |c| !tags. contains ( & c. tag ) ) . collect ( ) )
@@ -192,6 +197,11 @@ impl<'a> CommentsRef<'a> {
192197 . find ( |c| matches ! ( c. tag, CommentTag :: Inheritdoc ) )
193198 . and_then ( |c| c. value . split_whitespace ( ) . next ( ) )
194199 }
200+
201+ /// Filter a collection of comments and only return the custom tags.
202+ pub fn get_custom_tags ( & self ) -> Self {
203+ CommentsRef ( self . iter ( ) . cloned ( ) . filter ( |c| c. is_custom ( ) ) . collect ( ) )
204+ }
195205}
196206
197207impl < ' a > From < & ' a Comments > for CommentsRef < ' a > {
@@ -228,4 +238,32 @@ mod tests {
228238 assert_eq ! ( CommentTag :: from_str( "custom" ) , None ) ;
229239 assert_eq ! ( CommentTag :: from_str( "sometag" ) , None ) ;
230240 }
241+
242+ #[ test]
243+ fn test_is_custom ( ) {
244+ // Test custom tag.
245+ let custom_comment = Comment :: new (
246+ CommentTag :: from_str ( "custom:test" ) . unwrap ( ) ,
247+ "dummy custom tag" . to_owned ( ) ,
248+ ) ;
249+ assert ! ( custom_comment. is_custom( ) , "Custom tag should return true for is_custom" ) ;
250+
251+ // Test non-custom tags.
252+ let non_custom_tags = [
253+ CommentTag :: Title ,
254+ CommentTag :: Author ,
255+ CommentTag :: Notice ,
256+ CommentTag :: Dev ,
257+ CommentTag :: Param ,
258+ CommentTag :: Return ,
259+ CommentTag :: Inheritdoc ,
260+ ] ;
261+ for tag in non_custom_tags {
262+ let comment = Comment :: new ( tag. clone ( ) , "Non-custom comment" . to_string ( ) ) ;
263+ assert ! (
264+ !comment. is_custom( ) ,
265+ "Non-custom tag {tag:?} should return false for is_custom"
266+ ) ;
267+ }
268+ }
231269}
0 commit comments