Skip to content

Commit e3d86a3

Browse files
committed
refactor(core): Remove lifetime parameter from Arguments trait
Signed-off-by: Joshua Potts <[email protected]>
1 parent 58b46a2 commit e3d86a3

35 files changed

+170
-181
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ disallowed_methods = 'deny'
244244
level = 'warn'
245245
check-cfg = [
246246
'cfg(mariadb, values(any()))',
247+
'cfg(postgres_12)',
248+
'cfg(postgres_13)',
249+
'cfg(postgres_14)',
250+
'cfg(postgres_15)',
247251
'cfg(sqlite_ipaddr)',
248252
'cfg(sqlite_test_sqlcipher)',
249253
]

sqlx-core/src/any/arguments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ pub struct AnyArguments {
1212
pub values: AnyArgumentBuffer,
1313
}
1414

15-
impl<'q> Arguments<'q> for AnyArguments {
15+
impl Arguments for AnyArguments {
1616
type Database = Any;
1717

1818
fn reserve(&mut self, additional: usize, _size: usize) {
1919
self.values.0.reserve(additional);
2020
}
2121

22-
fn add<T>(&mut self, value: T) -> Result<(), BoxDynError>
22+
fn add<'t, T>(&mut self, value: T) -> Result<(), BoxDynError>
2323
where
24-
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>,
24+
T: Encode<'t, Self::Database> + Type<Self::Database>,
2525
{
2626
let _: IsNull = value.encode(&mut self.values)?;
2727
Ok(())
@@ -37,7 +37,7 @@ pub struct AnyArgumentBuffer(#[doc(hidden)] pub Vec<AnyValueKind>);
3737

3838
impl AnyArguments {
3939
#[doc(hidden)]
40-
pub fn convert_into<'a, A: Arguments<'a>>(self) -> Result<A, BoxDynError>
40+
pub fn convert_into<'a, A: Arguments>(self) -> Result<A, BoxDynError>
4141
where
4242
Option<i32>: Type<A::Database> + Encode<'a, A::Database>,
4343
Option<bool>: Type<A::Database> + Encode<'a, A::Database>,

sqlx-core/src/any/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl Database for Any {
2525
type Value = AnyValue;
2626
type ValueRef<'r> = AnyValueRef<'r>;
2727

28-
type Arguments<'q> = AnyArguments;
29-
type ArgumentBuffer<'q> = AnyArgumentBuffer;
28+
type Arguments = AnyArguments;
29+
type ArgumentBuffer = AnyArgumentBuffer;
3030

3131
type Statement = AnyStatement;
3232

sqlx-core/src/any/types/blob.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Type<Any> for [u8] {
1717
impl<'q> Encode<'q, Any> for &'q [u8] {
1818
fn encode_by_ref(
1919
&self,
20-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
20+
buf: &mut <Any as Database>::ArgumentBuffer,
2121
) -> Result<IsNull, BoxDynError> {
2222
buf.0.push(AnyValueKind::Blob(Arc::new(self.to_vec())));
2323
Ok(IsNull::No)
@@ -39,10 +39,10 @@ impl Type<Any> for Vec<u8> {
3939
}
4040
}
4141

42-
impl<'q> Encode<'q, Any> for Vec<u8> {
42+
impl Encode<'_, Any> for Vec<u8> {
4343
fn encode_by_ref(
4444
&self,
45-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
45+
buf: &mut <Any as Database>::ArgumentBuffer,
4646
) -> Result<IsNull, BoxDynError> {
4747
buf.0.push(AnyValueKind::Blob(Arc::new(self.clone())));
4848
Ok(IsNull::No)

sqlx-core/src/any/types/bool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ impl Type<Any> for bool {
1313
}
1414
}
1515

16-
impl<'q> Encode<'q, Any> for bool {
16+
impl Encode<'_, Any> for bool {
1717
fn encode_by_ref(
1818
&self,
19-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
19+
buf: &mut <Any as Database>::ArgumentBuffer,
2020
) -> Result<IsNull, BoxDynError> {
2121
buf.0.push(AnyValueKind::Bool(*self));
2222
Ok(IsNull::No)

sqlx-core/src/any/types/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ impl Type<Any> for f64 {
3737
}
3838
}
3939

40-
impl<'q> Encode<'q, Any> for f64 {
40+
impl Encode<'_, Any> for f64 {
4141
fn encode_by_ref(
4242
&self,
43-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
43+
buf: &mut <Any as Database>::ArgumentBuffer,
4444
) -> Result<IsNull, BoxDynError> {
4545
buf.0.push(AnyValueKind::Double(*self));
4646
Ok(IsNull::No)

sqlx-core/src/any/types/int.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ impl Type<Any> for i16 {
1717
}
1818
}
1919

20-
impl<'q> Encode<'q, Any> for i16 {
20+
impl Encode<'_, Any> for i16 {
2121
fn encode_by_ref(
2222
&self,
23-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
23+
buf: &mut <Any as Database>::ArgumentBuffer,
2424
) -> Result<IsNull, BoxDynError> {
2525
buf.0.push(AnyValueKind::SmallInt(*self));
2626
Ok(IsNull::No)
@@ -45,10 +45,10 @@ impl Type<Any> for i32 {
4545
}
4646
}
4747

48-
impl<'q> Encode<'q, Any> for i32 {
48+
impl Encode<'_, Any> for i32 {
4949
fn encode_by_ref(
5050
&self,
51-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
51+
buf: &mut <Any as Database>::ArgumentBuffer,
5252
) -> Result<IsNull, BoxDynError> {
5353
buf.0.push(AnyValueKind::Integer(*self));
5454
Ok(IsNull::No)
@@ -73,10 +73,10 @@ impl Type<Any> for i64 {
7373
}
7474
}
7575

76-
impl<'q> Encode<'q, Any> for i64 {
76+
impl Encode<'_, Any> for i64 {
7777
fn encode_by_ref(
7878
&self,
79-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
79+
buf: &mut <Any as Database>::ArgumentBuffer,
8080
) -> Result<IsNull, BoxDynError> {
8181
buf.0.push(AnyValueKind::BigInt(*self));
8282
Ok(IsNull::No)

sqlx-core/src/any/types/str.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Type<Any> for str {
1616
}
1717

1818
impl<'a> Encode<'a, Any> for &'a str {
19-
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer<'a>) -> Result<IsNull, BoxDynError>
19+
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError>
2020
where
2121
Self: Sized,
2222
{
@@ -26,7 +26,7 @@ impl<'a> Encode<'a, Any> for &'a str {
2626

2727
fn encode_by_ref(
2828
&self,
29-
buf: &mut <Any as Database>::ArgumentBuffer<'a>,
29+
buf: &mut <Any as Database>::ArgumentBuffer,
3030
) -> Result<IsNull, BoxDynError> {
3131
(*self).encode(buf)
3232
}
@@ -47,18 +47,15 @@ impl Type<Any> for String {
4747
}
4848
}
4949

50-
impl<'q> Encode<'q, Any> for String {
51-
fn encode(
52-
self,
53-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
54-
) -> Result<IsNull, BoxDynError> {
50+
impl Encode<'_, Any> for String {
51+
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError> {
5552
buf.0.push(AnyValueKind::Text(Arc::new(self)));
5653
Ok(IsNull::No)
5754
}
5855

5956
fn encode_by_ref(
6057
&self,
61-
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
58+
buf: &mut <Any as Database>::ArgumentBuffer,
6259
) -> Result<IsNull, BoxDynError> {
6360
buf.0.push(AnyValueKind::Text(Arc::new(self.clone())));
6461
Ok(IsNull::No)

sqlx-core/src/arguments.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use std::fmt::{self, Write};
99
/// A tuple of arguments to be sent to the database.
1010
// This lint is designed for general collections, but `Arguments` is not meant to be as such.
1111
#[allow(clippy::len_without_is_empty)]
12-
pub trait Arguments<'q>: Send + Sized + Default {
12+
pub trait Arguments: Send + Sized + Default {
1313
type Database: Database;
1414

1515
/// Reserves the capacity for at least `additional` more values (of `size` total bytes) to
1616
/// be added to the arguments without a reallocation.
1717
fn reserve(&mut self, additional: usize, size: usize);
1818

1919
/// Add the value to the end of the arguments.
20-
fn add<T>(&mut self, value: T) -> Result<(), BoxDynError>
20+
fn add<'t, T>(&mut self, value: T) -> Result<(), BoxDynError>
2121
where
22-
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>;
22+
T: Encode<'t, Self::Database> + Type<Self::Database>;
2323

2424
/// The number of arguments that were already added.
2525
fn len(&self) -> usize;
@@ -29,19 +29,17 @@ pub trait Arguments<'q>: Send + Sized + Default {
2929
}
3030
}
3131

32-
pub trait IntoArguments<'q, DB: Database>: Sized + Send {
33-
fn into_arguments(self) -> <DB as Database>::Arguments<'q>;
32+
pub trait IntoArguments<DB: Database>: Sized + Send {
33+
fn into_arguments(self) -> <DB as Database>::Arguments;
3434
}
3535

3636
// NOTE: required due to lack of lazy normalization
3737
#[macro_export]
3838
macro_rules! impl_into_arguments_for_arguments {
3939
($Arguments:path) => {
40-
impl<'q>
41-
$crate::arguments::IntoArguments<
42-
'q,
43-
<$Arguments as $crate::arguments::Arguments<'q>>::Database,
44-
> for $Arguments
40+
impl
41+
$crate::arguments::IntoArguments<<$Arguments as $crate::arguments::Arguments>::Database>
42+
for $Arguments
4543
{
4644
fn into_arguments(self) -> $Arguments {
4745
self
@@ -51,13 +49,10 @@ macro_rules! impl_into_arguments_for_arguments {
5149
}
5250

5351
/// used by the query macros to prevent supernumerary `.bind()` calls
54-
pub struct ImmutableArguments<'q, DB: Database>(pub <DB as Database>::Arguments<'q>);
52+
pub struct ImmutableArguments<DB: Database>(pub <DB as Database>::Arguments);
5553

56-
impl<'q, DB: Database> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> {
57-
fn into_arguments(self) -> <DB as Database>::Arguments<'q> {
54+
impl<DB: Database> IntoArguments<DB> for ImmutableArguments<DB> {
55+
fn into_arguments(self) -> <DB as Database>::Arguments {
5856
self.0
5957
}
6058
}
61-
62-
// TODO: Impl `IntoArguments` for &[&dyn Encode]
63-
// TODO: Impl `IntoArguments` for (impl Encode, ...) x16

sqlx-core/src/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ pub trait Database: 'static + Sized + Send + Debug {
9696
type ValueRef<'r>: ValueRef<'r, Database = Self>;
9797

9898
/// The concrete `Arguments` implementation for this database.
99-
type Arguments<'q>: Arguments<'q, Database = Self>;
99+
type Arguments: Arguments<Database = Self>;
100100
/// The concrete type used as a buffer for arguments while encoding.
101-
type ArgumentBuffer<'q>;
101+
type ArgumentBuffer;
102102

103103
/// The concrete `Statement` implementation for this database.
104104
type Statement: Statement<Database = Self>;

0 commit comments

Comments
 (0)