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
```
This commit is contained in:
Daniel 2024-03-14 12:37:28 -07:00 committed by GitHub
parent 9ba488c831
commit 0d0dddf1d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use crate::error::Error;
use std::fmt::Debug;
pub trait Column: 'static + Send + Sync + Debug {
type Database: Database;
type Database: Database<Column = Self>;
/// Gets the column ordinal.
///

View file

@ -11,7 +11,7 @@ use url::Url;
/// Represents a single database connection.
pub trait Connection: Send {
type Database: Database;
type Database: Database<Connection = Self>;
type Options: ConnectOptions<Connection = Self>;
@ -184,7 +184,7 @@ impl LogSettings {
}
pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug + Clone {
type Connection: Connection + ?Sized;
type Connection: Connection<Options = Self> + ?Sized;
/// Parse the `ConnectOptions` from a URL.
fn from_url(url: &Url) -> Result<Self, Error>;

View file

@ -12,7 +12,7 @@ use crate::value::ValueRef;
/// [`FromRow`]: crate::row::FromRow
/// [`Query::fetch`]: crate::query::Query::fetch
pub trait Row: Unpin + Send + Sync + 'static {
type Database: Database;
type Database: Database<Row = Self>;
/// Returns `true` if this row has no columns.
#[inline]

View file

@ -7,7 +7,7 @@ use std::borrow::Cow;
/// An owned value from the database.
pub trait Value {
type Database: Database;
type Database: Database<Value = Self>;
/// Get this value as a reference.
fn as_ref(&self) -> <Self::Database as Database>::ValueRef<'_>;