Skip to content

Commit

Permalink
relax lifetime bound of query types (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Oct 1, 2024
1 parent cf37816 commit 515f418
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
18 changes: 9 additions & 9 deletions postgres/src/driver/codec/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ impl<'s> Encode for &'s Statement {
}
}

impl<C> sealed::Sealed for StatementCreate<'_, C> {}
impl<C> sealed::Sealed for StatementCreate<'_, '_, C> {}

impl<'s, C> Encode for StatementCreate<'s, C>
impl<'c, C> Encode for StatementCreate<'_, 'c, C>
where
C: Prepare,
{
type Output = StatementCreateResponse<'s, C>;
type Output = StatementCreateResponse<'c, C>;

#[inline]
fn encode<const SYNC_MODE: bool>(self, buf: &mut BytesMut) -> Result<Self::Output, Error> {
Expand All @@ -87,13 +87,13 @@ where
}
}

impl<C> sealed::Sealed for StatementCreateBlocking<'_, C> {}
impl<C> sealed::Sealed for StatementCreateBlocking<'_, '_, C> {}

impl<'s, C> Encode for StatementCreateBlocking<'s, C>
impl<'c, C> Encode for StatementCreateBlocking<'_, 'c, C>
where
C: Prepare,
{
type Output = StatementCreateResponseBlocking<'s, C>;
type Output = StatementCreateResponseBlocking<'c, C>;

#[inline]
fn encode<const SYNC_MODE: bool>(self, buf: &mut BytesMut) -> Result<Self::Output, Error> {
Expand Down Expand Up @@ -147,14 +147,14 @@ where
}
}

impl<C, P> sealed::Sealed for StatementUnnamedQuery<'_, P, C> {}
impl<C, P> sealed::Sealed for StatementUnnamedQuery<'_, '_, P, C> {}

impl<'s, C, P> Encode for StatementUnnamedQuery<'s, P, C>
impl<'c, C, P> Encode for StatementUnnamedQuery<'_, 'c, P, C>
where
C: Prepare,
P: AsParams,
{
type Output = IntoRowStreamGuard<'s, C>;
type Output = IntoRowStreamGuard<'c, C>;

#[inline]
fn encode<const SYNC_MODE: bool>(self, buf: &mut BytesMut) -> Result<Self::Output, Error> {
Expand Down
6 changes: 2 additions & 4 deletions postgres/src/execute/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ where
}
}

impl<'c, 's, C> Execute<'c, C> for StatementNamed<'s>
impl<'c, C> Execute<'c, C> for StatementNamed<'_>
where
C: Prepare + 'c,
's: 'c,
{
type ExecuteOutput = ResultFuture<IntoGuardedFuture<'c, C>>;
type QueryOutput = Self::ExecuteOutput;
Expand Down Expand Up @@ -116,11 +115,10 @@ where
}
}

impl<'s, 'c, C, P> Execute<'c, C> for StatementUnnamedBind<'s, P>
impl<'c, C, P> Execute<'c, C> for StatementUnnamedBind<'_, P>
where
C: Prepare + 'c,
P: AsParams,
's: 'c,
{
type ExecuteOutput = ResultFuture<RowAffected>;
type QueryOutput = Ready<Result<RowStreamGuarded<'c, C>, Error>>;
Expand Down
10 changes: 4 additions & 6 deletions postgres/src/execute/sync_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ where
}
}

impl<'c, 's, C> ExecuteBlocking<'c, C> for StatementNamed<'s>
impl<'c, C> ExecuteBlocking<'c, C> for StatementNamed<'_>
where
C: Prepare + 'c,
's: 'c,
{
type ExecuteOutput = Result<StatementGuarded<'c, C>, Error>;
type QueryOutput = Self::ExecuteOutput;
Expand All @@ -72,7 +71,7 @@ where
impl<'s, C, P> ExecuteBlocking<'_, C> for StatementQuery<'s, P>
where
C: Query,
P: AsParams + 's,
P: AsParams,
{
type ExecuteOutput = Result<u64, Error>;
type QueryOutput = Result<RowStream<'s>, Error>;
Expand All @@ -89,11 +88,10 @@ where
}
}

impl<'s, 'c, C, P> ExecuteBlocking<'c, C> for StatementUnnamedBind<'s, P>
impl<'c, C, P> ExecuteBlocking<'c, C> for StatementUnnamedBind<'_, P>
where
C: Prepare + 'c,
P: AsParams + 'c,
's: 'c,
P: AsParams,
{
type ExecuteOutput = Result<u64, Error>;
type QueryOutput = Result<RowStreamGuarded<'c, C>, Error>;
Expand Down
24 changes: 12 additions & 12 deletions postgres/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ impl StatementNamed<'_> {
}
}

pub(crate) struct StatementCreate<'a, C> {
pub(crate) struct StatementCreate<'a, 'c, C> {
pub(crate) name: String,
pub(crate) stmt: &'a str,
pub(crate) types: &'a [Type],
pub(crate) cli: &'a C,
pub(crate) cli: &'c C,
}

impl<'a, C> From<(StatementNamed<'a>, &'a C)> for StatementCreate<'a, C> {
fn from((stmt, cli): (StatementNamed<'a>, &'a C)) -> Self {
impl<'a, 'c, C> From<(StatementNamed<'a>, &'c C)> for StatementCreate<'a, 'c, C> {
fn from((stmt, cli): (StatementNamed<'a>, &'c C)) -> Self {
Self {
name: StatementNamed::name(),
stmt: stmt.stmt,
Expand All @@ -213,15 +213,15 @@ impl<'a, C> From<(StatementNamed<'a>, &'a C)> for StatementCreate<'a, C> {
}
}

pub(crate) struct StatementCreateBlocking<'a, C> {
pub(crate) struct StatementCreateBlocking<'a, 'c, C> {
pub(crate) name: String,
pub(crate) stmt: &'a str,
pub(crate) types: &'a [Type],
pub(crate) cli: &'a C,
pub(crate) cli: &'c C,
}

impl<'a, C> From<(StatementNamed<'a>, &'a C)> for StatementCreateBlocking<'a, C> {
fn from((stmt, cli): (StatementNamed<'a>, &'a C)) -> Self {
impl<'a, 'c, C> From<(StatementNamed<'a>, &'c C)> for StatementCreateBlocking<'a, 'c, C> {
fn from((stmt, cli): (StatementNamed<'a>, &'c C)) -> Self {
Self {
name: StatementNamed::name(),
stmt: stmt.stmt,
Expand Down Expand Up @@ -273,15 +273,15 @@ pub struct StatementUnnamedBind<'a, P> {
params: P,
}

pub(crate) struct StatementUnnamedQuery<'a, P, C> {
pub(crate) struct StatementUnnamedQuery<'a, 'c, P, C> {
pub(crate) stmt: &'a str,
pub(crate) types: &'a [Type],
pub(crate) params: P,
pub(crate) cli: &'a C,
pub(crate) cli: &'c C,
}

impl<'a, P, C> From<(StatementUnnamedBind<'a, P>, &'a C)> for StatementUnnamedQuery<'a, P, C> {
fn from((bind, cli): (StatementUnnamedBind<'a, P>, &'a C)) -> Self {
impl<'a, 'c, P, C> From<(StatementUnnamedBind<'a, P>, &'c C)> for StatementUnnamedQuery<'a, 'c, P, C> {
fn from((bind, cli): (StatementUnnamedBind<'a, P>, &'c C)) -> Self {
Self {
stmt: bind.stmt,
types: bind.types,
Expand Down

0 comments on commit 515f418

Please sign in to comment.