use GAT to elide StreamTrait lifetime (#1161)

This commit is contained in:
Marco Napetti 2022-11-06 05:55:21 +01:00 committed by GitHub
parent 9952aa6740
commit 9d25ee9ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 19 deletions

View File

@ -34,15 +34,17 @@ pub trait ConnectionTrait: Sync {
}
/// Stream query results
pub trait StreamTrait<'a>: Send + Sync {
pub trait StreamTrait: Send + Sync {
/// Create a stream for the [QueryResult]
type Stream: Stream<Item = Result<QueryResult, DbErr>> + Send;
type Stream<'a>: Stream<Item = Result<QueryResult, DbErr>> + Send
where
Self: 'a;
/// Execute a [Statement] and return a stream of results
fn stream(
fn stream<'a>(
&'a self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>>;
) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>>;
}
/// Spawn database transaction

View File

@ -165,15 +165,15 @@ impl ConnectionTrait for DatabaseConnection {
}
#[async_trait::async_trait]
impl<'a> StreamTrait<'a> for DatabaseConnection {
type Stream = crate::QueryStream;
impl StreamTrait for DatabaseConnection {
type Stream<'a> = crate::QueryStream;
#[instrument(level = "trace")]
#[allow(unused_variables, unreachable_code)]
fn stream(
fn stream<'a>(
&'a self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>> {
) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>> {
Box::pin(async move {
Ok(match self {
#[cfg(feature = "sqlx-mysql")]

View File

@ -388,16 +388,14 @@ impl ConnectionTrait for DatabaseTransaction {
}
}
#[async_trait::async_trait]
#[allow(unused_variables)]
impl<'a> StreamTrait<'a> for DatabaseTransaction {
type Stream = TransactionStream<'a>;
impl StreamTrait for DatabaseTransaction {
type Stream<'a> = TransactionStream<'a>;
#[instrument(level = "trace")]
fn stream(
fn stream<'a>(
&'a self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>> {
) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>> {
Box::pin(async move {
let conn = self.conn.lock().await;
Ok(crate::TransactionStream::build(

View File

@ -275,7 +275,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<E::Model, DbErr>> + 'b + Send, DbErr>
where
C: ConnectionTrait + StreamTrait<'a> + Send,
C: ConnectionTrait + StreamTrait + Send,
{
self.into_model().stream(db).await
}
@ -329,7 +329,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<(E::Model, Option<F::Model>), DbErr>> + 'b, DbErr>
where
C: ConnectionTrait + StreamTrait<'a> + Send,
C: ConnectionTrait + StreamTrait + Send,
{
self.into_model().stream(db).await
}
@ -367,7 +367,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<(E::Model, Option<F::Model>), DbErr>> + 'b + Send, DbErr>
where
C: ConnectionTrait + StreamTrait<'a> + Send,
C: ConnectionTrait + StreamTrait + Send,
{
self.into_model().stream(db).await
}
@ -453,7 +453,7 @@ where
db: &'a C,
) -> Result<Pin<Box<dyn Stream<Item = Result<S::Item, DbErr>> + 'b + Send>>, DbErr>
where
C: ConnectionTrait + StreamTrait<'a> + Send,
C: ConnectionTrait + StreamTrait + Send,
S: 'b,
S::Item: Send,
{
@ -739,7 +739,7 @@ where
db: &'a C,
) -> Result<Pin<Box<dyn Stream<Item = Result<S::Item, DbErr>> + 'b + Send>>, DbErr>
where
C: ConnectionTrait + StreamTrait<'a> + Send,
C: ConnectionTrait + StreamTrait + Send,
S: 'b,
S::Item: Send,
{