@@ -40,6 +40,7 @@ impl AsRef<str> for FieldType {
4040 }
4141}
4242
43+ /// An aggregation.
4344#[ derive( Serialize , Deserialize , Debug , Eq , PartialEq ) ]
4445pub struct Agg {
4546 // Name of the aggregation
@@ -267,18 +268,29 @@ impl Table {
267268 & self . columns
268269 }
269270
271+ /// Returns true if the first column is empty.
272+ #[ must_use]
273+ pub fn is_empty ( & self ) -> bool {
274+ self . len ( ) == 0
275+ }
276+
270277 /// Returns the maximum length of the first column
271278 pub fn len ( & self ) -> usize {
272279 self . columns . first ( ) . map ( Vec :: len) . unwrap_or_default ( )
273280 }
274281
282+ /// Returns a single row from the table.
283+ #[ must_use]
275284 pub fn get_row ( & self , row : usize ) -> Option < Row > {
276285 if self . len ( ) > row {
277286 Some ( Row { table : self , row } )
278287 } else {
279288 None
280289 }
281290 }
291+
292+ /// Returns an iterator over the rows.
293+ #[ must_use]
282294 pub fn iter ( & self ) -> RowIter {
283295 RowIter {
284296 table : self ,
@@ -287,6 +299,14 @@ impl Table {
287299 }
288300}
289301
302+ impl < ' table > IntoIterator for & ' table Table {
303+ type Item = Row < ' table > ;
304+ type IntoIter = RowIter < ' table > ;
305+ fn into_iter ( self ) -> Self :: IntoIter {
306+ self . iter ( )
307+ }
308+ }
309+
290310/// Iterator over the rows of a table.
291311pub struct RowIter < ' table > {
292312 table : & ' table Table ,
@@ -317,10 +337,10 @@ impl<'table> Iterator for RowIter<'table> {
317337 where
318338 Self : Sized ,
319339 {
320- if self . table . len ( ) > 0 {
321- self . table . get_row ( self . table . len ( ) - 1 )
322- } else {
340+ if self . table . is_empty ( ) {
323341 None
342+ } else {
343+ self . table . get_row ( self . table . len ( ) - 1 )
324344 }
325345 }
326346}
@@ -333,6 +353,7 @@ pub struct Row<'table> {
333353
334354impl < ' table > Row < ' table > {
335355 /// Returns the value of the row by name
356+ #[ must_use]
336357 pub fn get_field ( & self , field : & str ) -> Option < & JsonValue > {
337358 let mut index = None ;
338359
@@ -346,6 +367,7 @@ impl<'table> Row<'table> {
346367 self . get ( index?)
347368 }
348369 /// Returns the value of the row.
370+ #[ must_use]
349371 pub fn get ( & self , column : usize ) -> Option < & JsonValue > {
350372 self . table . columns . get ( column) . and_then ( |c| c. get ( self . row ) )
351373 }
@@ -365,6 +387,14 @@ impl<'table> Row<'table> {
365387 }
366388}
367389
390+ impl < ' table > IntoIterator for & Row < ' table > {
391+ type Item = Option < & ' table JsonValue > ;
392+ type IntoIter = FieldIter < ' table > ;
393+ fn into_iter ( self ) -> Self :: IntoIter {
394+ self . iter ( )
395+ }
396+ }
397+
368398/// Iterator over the fields of a row.
369399pub struct FieldIter < ' table > {
370400 table : & ' table Table ,
0 commit comments