@@ -3,6 +3,7 @@ use std::fmt;
3
3
use std:: ops:: Deref ;
4
4
use std:: sync:: Arc ;
5
5
6
+ /// A result set from a Noria query.
6
7
#[ derive( PartialEq , Eq ) ]
7
8
pub struct Results {
8
9
results : Vec < Vec < DataType > > ,
@@ -14,6 +15,7 @@ impl Results {
14
15
Self { results, columns }
15
16
}
16
17
18
+ /// Iterate over references to the returned rows.
17
19
pub fn iter ( & self ) -> ResultIter < ' _ > {
18
20
self . into_iter ( )
19
21
}
@@ -37,6 +39,10 @@ impl PartialEq<&'_ Vec<Vec<DataType>>> for Results {
37
39
}
38
40
}
39
41
42
+ /// A reference to a row in a result set.
43
+ ///
44
+ /// You can access fields either by numerical index or by field index.
45
+ /// If you want to also perform type conversion, use [`ResultRow::get`].
40
46
#[ derive( PartialEq , Eq ) ]
41
47
pub struct ResultRow < ' a > {
42
48
result : & ' a Vec < DataType > ,
@@ -68,6 +74,11 @@ impl std::ops::Index<&'_ str> for ResultRow<'_> {
68
74
}
69
75
70
76
impl < ' a > ResultRow < ' a > {
77
+ /// Retrieve the field of the result by the given name as a `T`.
78
+ ///
79
+ /// Returns `None` if the given field does not exist.
80
+ ///
81
+ /// Panics if the value at the given field cannot be turned into a `T`.
71
82
pub fn get < T > ( & self , field : & str ) -> Option < T >
72
83
where
73
84
& ' a DataType : Into < T > ,
@@ -203,6 +214,10 @@ impl DoubleEndedIterator for ResultIntoIter {
203
214
}
204
215
}
205
216
217
+ /// A single row from a result set.
218
+ ///
219
+ /// You can access fields either by numerical index or by field index.
220
+ /// If you want to also perform type conversion, use [`Row::get`].
206
221
#[ derive( PartialEq , Eq ) ]
207
222
pub struct Row {
208
223
row : Vec < DataType > ,
@@ -281,6 +296,11 @@ impl std::ops::Index<&'_ str> for Row {
281
296
}
282
297
283
298
impl Row {
299
+ /// Retrieve the field of the result by the given name as a `T`.
300
+ ///
301
+ /// Returns `None` if the given field does not exist.
302
+ ///
303
+ /// Panics if the value at the given field cannot be turned into a `T`.
284
304
pub fn get < T > ( & self , field : & str ) -> Option < T >
285
305
where
286
306
for < ' a > & ' a DataType : Into < T > ,
0 commit comments