Add must_use attribute to iterators

This commit is contained in:
Michael Sproul 2020-09-02 16:15:25 +10:00
parent 45903324e5
commit d7e0536b41
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914

View File

@ -6,6 +6,7 @@ use super::{Error, Result, Statement};
use crate::types::{FromSql, FromSqlError, ValueRef}; use crate::types::{FromSql, FromSqlError, ValueRef};
/// An handle for the resulting rows of a query. /// An handle for the resulting rows of a query.
#[must_use = "Rows is lazy and will do nothing unless consumed"]
pub struct Rows<'stmt> { pub struct Rows<'stmt> {
pub(crate) stmt: Option<&'stmt Statement<'stmt>>, pub(crate) stmt: Option<&'stmt Statement<'stmt>>,
row: Option<Row<'stmt>>, row: Option<Row<'stmt>>,
@ -96,6 +97,7 @@ impl Drop for Rows<'_> {
} }
/// `F` is used to tranform the _streaming_ iterator into a _fallible_ iterator. /// `F` is used to tranform the _streaming_ iterator into a _fallible_ iterator.
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Map<'stmt, F> { pub struct Map<'stmt, F> {
rows: Rows<'stmt>, rows: Rows<'stmt>,
f: F, f: F,
@ -119,6 +121,7 @@ where
/// An iterator over the mapped resulting rows of a query. /// An iterator over the mapped resulting rows of a query.
/// ///
/// `F` is used to tranform the _streaming_ iterator into a _standard_ iterator. /// `F` is used to tranform the _streaming_ iterator into a _standard_ iterator.
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct MappedRows<'stmt, F> { pub struct MappedRows<'stmt, F> {
rows: Rows<'stmt>, rows: Rows<'stmt>,
map: F, map: F,
@ -150,6 +153,7 @@ where
/// An iterator over the mapped resulting rows of a query, with an Error type /// An iterator over the mapped resulting rows of a query, with an Error type
/// unifying with Error. /// unifying with Error.
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct AndThenRows<'stmt, F> { pub struct AndThenRows<'stmt, F> {
rows: Rows<'stmt>, rows: Rows<'stmt>,
map: F, map: F,