@@ -108,7 +108,7 @@ impl KdlDocument {
108
108
self . get ( name) . and_then ( |node| node. get ( 0 ) )
109
109
}
110
110
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
112
112
/// matching name. This is a shorthand utility for cases where a document
113
113
/// is being used as a key/value store and the value is expected to be
114
114
/// array-ish.
@@ -127,16 +127,18 @@ impl KdlDocument {
127
127
/// ```rust
128
128
/// # use kdl::{KdlDocument, KdlValue};
129
129
/// # 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
+ /// );
131
134
/// ```
132
- pub fn get_args ( & self , name : & str ) -> Vec < & KdlValue > {
135
+ pub fn iter_args ( & self , name : & str ) -> impl Iterator < Item = & KdlValue > {
133
136
self . get ( name)
134
137
. map ( |n| n. entries ( ) )
135
138
. unwrap_or_default ( )
136
139
. iter ( )
137
140
. filter ( |e| e. name ( ) . is_none ( ) )
138
141
. map ( |e| e. value ( ) )
139
- . collect ( )
140
142
}
141
143
142
144
/// Gets a mutable reference to the first argument (value) of the first
@@ -164,17 +166,19 @@ impl KdlDocument {
164
166
/// ```rust
165
167
/// # use kdl::{KdlDocument, KdlValue};
166
168
/// # 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
+ /// );
168
173
/// ```
169
- pub fn get_dash_args ( & self , name : & str ) -> Vec < & KdlValue > {
174
+ pub fn iter_dash_args ( & self , name : & str ) -> impl Iterator < Item = & KdlValue > {
170
175
self . get ( name)
171
176
. and_then ( |n| n. children ( ) )
172
177
. map ( |doc| doc. nodes ( ) )
173
178
. unwrap_or_default ( )
174
179
. iter ( )
175
180
. filter ( |e| e. name ( ) . value ( ) == "-" )
176
181
. filter_map ( |e| e. get ( 0 ) )
177
- . collect ( )
178
182
}
179
183
180
184
/// Returns a reference to this document's child nodes.
@@ -441,8 +445,8 @@ second_node /* This time, the comment is here */ param=153 {
441
445
/* block comment */
442
446
inline /*comment*/ here
443
447
another /-comment there
444
-
445
-
448
+
449
+
446
450
after some whitespace
447
451
trailing /* multiline */
448
452
trailing // single line
@@ -480,7 +484,7 @@ final;";
480
484
481
485
assert_eq ! ( doc. get_arg( "foo" ) , Some ( & 1 . into( ) ) ) ;
482
486
assert_eq ! (
483
- doc. get_dash_args ( "foo" ) ,
487
+ doc. iter_dash_args ( "foo" ) . collect :: < Vec < & KdlValue >> ( ) ,
484
488
vec![ & 1 . into( ) , & 2 . into( ) , & "three" . into( ) ]
485
489
) ;
486
490
assert_eq ! (
0 commit comments