Skip to content

Commit

Permalink
Merge pull request diesel-rs#2967 from Ten0/no_unnecessary_iter_boxing
Browse files Browse the repository at this point in the history
No unnecessary boxing in load_iter
  • Loading branch information
Ten0 authored Dec 8, 2021
2 parents 925110b + 8fb5e56 commit c2a5316
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ pub mod helper_types {
#[cfg(feature = "postgres_backend")]
pub type SelectFromOnly<T> =
crate::query_builder::SelectStatement<crate::pg::query_builder::only_clause::Only<T>>;

/// [`Iterator`](std::iter::Iterator) of [`QueryResult<U>`](crate::result::QueryResult)
///
/// See [`RunQueryDsl::load_iter`] for more information
pub type LoadIter<'a, Q, Conn, U> = <Q as load_dsl::LoadQueryGatWorkaround<'a, Conn, U>>::Ret;
}

pub mod prelude {
Expand Down
13 changes: 6 additions & 7 deletions diesel/src/query_dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,9 +1405,11 @@ pub trait RunQueryDsl<Conn>: Sized {
self.internal_load(conn)?.collect()
}

/// Executes the given query, returning a [`Iterator`] with the returned rows.
/// Executes the given query, returning an [`Iterator`] with the returned rows.
///
/// **You should normally prefer to use [`RunQueryDsl::load`] instead**. This method
/// The iterator's item is [`QueryResult<U>`](crate::result::QueryResult).
///
/// You should normally prefer to use [`RunQueryDsl::load`] instead. This method
/// is provided for situations where the result needs to be collected into a different
/// container than a [`Vec`]
///
Expand Down Expand Up @@ -1503,15 +1505,12 @@ pub trait RunQueryDsl<Conn>: Sized {
/// # Ok(())
/// # }
/// ```
fn load_iter<'a, U>(
self,
conn: &'a mut Conn,
) -> QueryResult<Box<dyn Iterator<Item = QueryResult<U>> + 'a>>
fn load_iter<'a, U>(self, conn: &'a mut Conn) -> QueryResult<LoadIter<'a, Self, Conn, U>>
where
U: 'a,
Self: LoadQuery<Conn, U> + 'a,
{
self.internal_load(conn).map(|i| Box::new(i) as Box<_>)
self.internal_load(conn)
}

/// Runs the command, and returns the affected row.
Expand Down

0 comments on commit c2a5316

Please sign in to comment.