Skip to content

Commit 938deac

Browse files
committed
Document new results types
1 parent baf7a25 commit 938deac

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

noria/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
//! binary MySQL protocol, which provides a compatibility layer for applications that wish to
104104
//! continue to issue ad-hoc MySQL queries through existing MySQL client libraries.
105105
#![feature(type_alias_impl_trait)]
106-
#![warn(missing_docs)]
106+
#![deny(missing_docs)]
107107
#![deny(unused_extern_crates)]
108108
#![deny(unreachable_pub)]
109109
#![warn(rust_2018_idioms)]
@@ -149,6 +149,7 @@ pub mod prelude {
149149
pub use super::View;
150150
}
151151

152+
/// Wrapper types for Noria query results.
152153
pub mod results {
153154
pub use super::view::results::{ResultRow, Results, Row};
154155
}

noria/src/view/results.rs

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt;
33
use std::ops::Deref;
44
use std::sync::Arc;
55

6+
/// A result set from a Noria query.
67
#[derive(PartialEq, Eq)]
78
pub struct Results {
89
results: Vec<Vec<DataType>>,
@@ -14,6 +15,7 @@ impl Results {
1415
Self { results, columns }
1516
}
1617

18+
/// Iterate over references to the returned rows.
1719
pub fn iter(&self) -> ResultIter<'_> {
1820
self.into_iter()
1921
}
@@ -37,6 +39,10 @@ impl PartialEq<&'_ Vec<Vec<DataType>>> for Results {
3739
}
3840
}
3941

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`].
4046
#[derive(PartialEq, Eq)]
4147
pub struct ResultRow<'a> {
4248
result: &'a Vec<DataType>,
@@ -68,6 +74,11 @@ impl std::ops::Index<&'_ str> for ResultRow<'_> {
6874
}
6975

7076
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`.
7182
pub fn get<T>(&self, field: &str) -> Option<T>
7283
where
7384
&'a DataType: Into<T>,
@@ -203,6 +214,10 @@ impl DoubleEndedIterator for ResultIntoIter {
203214
}
204215
}
205216

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`].
206221
#[derive(PartialEq, Eq)]
207222
pub struct Row {
208223
row: Vec<DataType>,
@@ -281,6 +296,11 @@ impl std::ops::Index<&'_ str> for Row {
281296
}
282297

283298
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`.
284304
pub fn get<T>(&self, field: &str) -> Option<T>
285305
where
286306
for<'a> &'a DataType: Into<T>,

0 commit comments

Comments
 (0)