@@ -108,7 +108,7 @@ impl KdlDocument {
108108 self . get ( name) . and_then ( |node| node. get ( 0 ) )
109109 }
110110
111- /// Gets the all node arguments (value) of the first child node with a
111+ /// Returns an iterator of the all node arguments (value) of the first child node with a
112112 /// matching name. This is a shorthand utility for cases where a document
113113 /// is being used as a key/value store and the value is expected to be
114114 /// array-ish.
@@ -127,16 +127,18 @@ impl KdlDocument {
127127 /// ```rust
128128 /// # use kdl::{KdlDocument, KdlValue};
129129 /// # let doc: KdlDocument = "foo 1 2 3\nbar #false".parse().unwrap();
130- /// assert_eq!(doc.get_args("foo"), vec![&1.into(), &2.into(), &3.into()]);
130+ /// assert_eq!(
131+ /// doc.iter_args("foo").collect::<Vec<&KdlValue>>(),
132+ /// vec![&1.into(), &2.into(), &3.into()]
133+ /// );
131134 /// ```
132- pub fn get_args ( & self , name : & str ) -> Vec < & KdlValue > {
135+ pub fn iter_args ( & self , name : & str ) -> impl Iterator < Item = & KdlValue > {
133136 self . get ( name)
134137 . map ( |n| n. entries ( ) )
135138 . unwrap_or_default ( )
136139 . iter ( )
137140 . filter ( |e| e. name ( ) . is_none ( ) )
138141 . map ( |e| e. value ( ) )
139- . collect ( )
140142 }
141143
142144 /// Gets a mutable reference to the first argument (value) of the first
@@ -164,17 +166,19 @@ impl KdlDocument {
164166 /// ```rust
165167 /// # use kdl::{KdlDocument, KdlValue};
166168 /// # let doc: KdlDocument = "foo {\n - 1\n - 2\n - #false\n}".parse().unwrap();
167- /// assert_eq!(doc.get_dash_args("foo"), vec![&1.into(), &2.into(), &false.into()]);
169+ /// assert_eq!(
170+ /// doc.iter_dash_args("foo").collect::<Vec<&KdlValue>>(),
171+ /// vec![&1.into(), &2.into(), &false.into()]
172+ /// );
168173 /// ```
169- pub fn get_dash_args ( & self , name : & str ) -> Vec < & KdlValue > {
174+ pub fn iter_dash_args ( & self , name : & str ) -> impl Iterator < Item = & KdlValue > {
170175 self . get ( name)
171176 . and_then ( |n| n. children ( ) )
172177 . map ( |doc| doc. nodes ( ) )
173178 . unwrap_or_default ( )
174179 . iter ( )
175180 . filter ( |e| e. name ( ) . value ( ) == "-" )
176181 . filter_map ( |e| e. get ( 0 ) )
177- . collect ( )
178182 }
179183
180184 /// Returns a reference to this document's child nodes.
@@ -441,8 +445,8 @@ second_node /* This time, the comment is here */ param=153 {
441445 /* block comment */
442446 inline /*comment*/ here
443447 another /-comment there
444-
445-
448+
449+
446450 after some whitespace
447451 trailing /* multiline */
448452 trailing // single line
@@ -480,7 +484,7 @@ final;";
480484
481485 assert_eq ! ( doc. get_arg( "foo" ) , Some ( & 1 . into( ) ) ) ;
482486 assert_eq ! (
483- doc. get_dash_args ( "foo" ) ,
487+ doc. iter_dash_args ( "foo" ) . collect :: < Vec < & KdlValue >> ( ) ,
484488 vec![ & 1 . into( ) , & 2 . into( ) , & "three" . into( ) ]
485489 ) ;
486490 assert_eq ! (
0 commit comments