Skip to content

Commit 0d0dddf

Browse files
authored
Constrain cyclic associated types (#2702)
Add bounds such that cyclic associated types are equal to themselves. ``` <T as Connection>::Database as Database>::Connection == T <T as ConnectOptions>::Connection as Connection>::Options == T <T as Row>::Database as Database>::Row == T <T as Column>::Database as Database>::Column == T <T as Value>::Database as Database>::Value == T ```
1 parent 9ba488c commit 0d0dddf

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

sqlx-core/src/column.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::error::Error;
44
use std::fmt::Debug;
55

66
pub trait Column: 'static + Send + Sync + Debug {
7-
type Database: Database;
7+
type Database: Database<Column = Self>;
88

99
/// Gets the column ordinal.
1010
///

sqlx-core/src/connection.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use url::Url;
1111

1212
/// Represents a single database connection.
1313
pub trait Connection: Send {
14-
type Database: Database;
14+
type Database: Database<Connection = Self>;
1515

1616
type Options: ConnectOptions<Connection = Self>;
1717

@@ -184,7 +184,7 @@ impl LogSettings {
184184
}
185185

186186
pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug + Clone {
187-
type Connection: Connection + ?Sized;
187+
type Connection: Connection<Options = Self> + ?Sized;
188188

189189
/// Parse the `ConnectOptions` from a URL.
190190
fn from_url(url: &Url) -> Result<Self, Error>;

sqlx-core/src/row.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::value::ValueRef;
1212
/// [`FromRow`]: crate::row::FromRow
1313
/// [`Query::fetch`]: crate::query::Query::fetch
1414
pub trait Row: Unpin + Send + Sync + 'static {
15-
type Database: Database;
15+
type Database: Database<Row = Self>;
1616

1717
/// Returns `true` if this row has no columns.
1818
#[inline]

sqlx-core/src/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::borrow::Cow;
77

88
/// An owned value from the database.
99
pub trait Value {
10-
type Database: Database;
10+
type Database: Database<Value = Self>;
1111

1212
/// Get this value as a reference.
1313
fn as_ref(&self) -> <Self::Database as Database>::ValueRef<'_>;

0 commit comments

Comments
 (0)