diff --git a/sqlx-core/src/any/mod.rs b/sqlx-core/src/any/mod.rs index 214a2a69..5acc023f 100644 --- a/sqlx-core/src/any/mod.rs +++ b/sqlx-core/src/any/mod.rs @@ -54,7 +54,6 @@ impl_acquire!(Any, AnyConnection); impl_column_index_for_row!(AnyRow); impl_column_index_for_statement!(AnyStatement); impl_into_maybe_pool!(Any, AnyConnection); -impl_map_row!(Any, AnyRow); // required because some databases have a different handling of NULL impl_encode_for_option!(Any); diff --git a/sqlx-core/src/mssql/mod.rs b/sqlx-core/src/mssql/mod.rs index 4c7fa941..3c118216 100644 --- a/sqlx-core/src/mssql/mod.rs +++ b/sqlx-core/src/mssql/mod.rs @@ -36,7 +36,6 @@ pub type MssqlPool = crate::pool::Pool; impl_into_arguments_for_arguments!(MssqlArguments); impl_executor_for_pool_connection!(Mssql, MssqlConnection, MssqlRow); impl_executor_for_transaction!(Mssql, MssqlRow); -impl_map_row!(Mssql, MssqlRow); impl_acquire!(Mssql, MssqlConnection); impl_column_index_for_row!(MssqlRow); impl_column_index_for_statement!(MssqlStatement); diff --git a/sqlx-core/src/mysql/mod.rs b/sqlx-core/src/mysql/mod.rs index 95e3b43a..023e95de 100644 --- a/sqlx-core/src/mysql/mod.rs +++ b/sqlx-core/src/mysql/mod.rs @@ -43,7 +43,6 @@ pub type MySqlPoolOptions = crate::pool::PoolOptions; impl_into_arguments_for_arguments!(MySqlArguments); impl_executor_for_pool_connection!(MySql, MySqlConnection, MySqlRow); impl_executor_for_transaction!(MySql, MySqlRow); -impl_map_row!(MySql, MySqlRow); impl_acquire!(MySql, MySqlConnection); impl_column_index_for_row!(MySqlRow); impl_column_index_for_statement!(MySqlStatement); diff --git a/sqlx-core/src/postgres/mod.rs b/sqlx-core/src/postgres/mod.rs index ff20b28d..59cbf7ad 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -44,7 +44,6 @@ pub type PgPoolOptions = crate::pool::PoolOptions; impl_into_arguments_for_arguments!(PgArguments); impl_executor_for_pool_connection!(Postgres, PgConnection, PgRow); impl_executor_for_transaction!(Postgres, PgRow); -impl_map_row!(Postgres, PgRow); impl_acquire!(Postgres, PgConnection); impl_column_index_for_row!(PgRow); impl_column_index_for_statement!(PgStatement); diff --git a/sqlx-core/src/query.rs b/sqlx-core/src/query.rs index dbfe2ea7..54f10699 100644 --- a/sqlx-core/src/query.rs +++ b/sqlx-core/src/query.rs @@ -115,12 +115,15 @@ where /// The [`query_as`](super::query_as::query_as) method will construct a mapped query using /// a [`FromRow`](super::from_row::FromRow) implementation. #[inline] - pub fn map(self, f: F) -> Map<'q, DB, impl TryMapRow, A> + pub fn map( + self, + mut f: F, + ) -> Map<'q, DB, impl FnMut(DB::Row) -> Result + Send, A> where - F: MapRow, + F: FnMut(DB::Row) -> O + Send, O: Unpin, { - self.try_map(MapRowAdapter(f)) + self.try_map(move |row| Ok(f(row))) } /// Map each row in the result to another type. @@ -128,9 +131,10 @@ where /// The [`query_as`](super::query_as::query_as) method will construct a mapped query using /// a [`FromRow`](super::from_row::FromRow) implementation. #[inline] - pub fn try_map(self, f: F) -> Map<'q, DB, F, A> + pub fn try_map(self, f: F) -> Map<'q, DB, F, A> where - F: TryMapRow, + F: FnMut(DB::Row) -> Result + Send, + O: Unpin, { Map { inner: self, @@ -252,7 +256,7 @@ where impl<'q, DB, F, O, A> Map<'q, DB, F, A> where DB: Database, - F: TryMapRow, + F: FnMut(DB::Row) -> Result + Send, O: Send + Unpin, A: 'q + Send + IntoArguments<'q, DB>, { @@ -295,7 +299,7 @@ where r#yield!(match v { Either::Left(v) => Either::Left(v), Either::Right(row) => { - Either::Right(self.mapper.try_map_row(row)?) + Either::Right((self.mapper)(row)?) } }); } @@ -345,47 +349,13 @@ where let row = executor.fetch_optional(self.inner).await?; if let Some(row) = row { - self.mapper.try_map_row(row).map(Some) + (self.mapper)(row).map(Some) } else { Ok(None) } } } -// A (hopefully) temporary workaround for an internal compiler error (ICE) involving higher-ranked -// trait bounds (HRTBs), associated types and closures. -// -// See https://github.com/rust-lang/rust/issues/62529 - -pub trait TryMapRow: Send { - type Output: Unpin; - - fn try_map_row(&mut self, row: DB::Row) -> Result; -} - -pub trait MapRow: Send { - type Output: Unpin; - - fn map_row(&mut self, row: DB::Row) -> Self::Output; -} - -// A private adapter that implements [MapRow] in terms of [TryMapRow] -// Just ends up Ok wrapping it - -struct MapRowAdapter(F); - -impl TryMapRow for MapRowAdapter -where - O: Unpin, - F: MapRow, -{ - type Output = O; - - fn try_map_row(&mut self, row: DB::Row) -> Result { - Ok(self.0.map_row(row)) - } -} - // Make a SQL query from a statement. pub(crate) fn query_statement<'q, DB>( statement: &'q >::Statement, @@ -444,30 +414,3 @@ where persistent: true, } } - -#[allow(unused_macros)] -macro_rules! impl_map_row { - ($DB:ident, $R:ident) => { - impl crate::query::MapRow<$DB> for F - where - F: Send + FnMut($R) -> O, - { - type Output = O; - - fn map_row(&mut self, row: $R) -> O { - (self)(row) - } - } - - impl crate::query::TryMapRow<$DB> for F - where - F: Send + FnMut($R) -> Result, - { - type Output = O; - - fn try_map_row(&mut self, row: $R) -> Result { - (self)(row) - } - } - }; -} diff --git a/sqlx-core/src/sqlite/mod.rs b/sqlx-core/src/sqlite/mod.rs index 48b9795b..4aae7bc4 100644 --- a/sqlx-core/src/sqlite/mod.rs +++ b/sqlx-core/src/sqlite/mod.rs @@ -45,7 +45,6 @@ pub type SqlitePoolOptions = crate::pool::PoolOptions; impl_into_arguments_for_arguments!(SqliteArguments<'q>); impl_executor_for_pool_connection!(Sqlite, SqliteConnection, SqliteRow); impl_executor_for_transaction!(Sqlite, SqliteRow); -impl_map_row!(Sqlite, SqliteRow); impl_column_index_for_row!(SqliteRow); impl_column_index_for_statement!(SqliteStatement); impl_acquire!(Sqlite, SqliteConnection); diff --git a/src/lib.rs b/src/lib.rs index 30ded66a..e3bb60a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,7 +130,6 @@ pub use self::decode::Decode; /// Types and traits for the `query` family of functions and macros. pub mod query { pub use sqlx_core::query::{Map, Query}; - pub use sqlx_core::query::{MapRow, TryMapRow}; pub use sqlx_core::query_as::QueryAs; pub use sqlx_core::query_scalar::QueryScalar; }