mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
Add DecodeOwned to help with trait bounds on owned data
This commit is contained in:
parent
f562e919b7
commit
24d62dd464
@ -1,8 +1,8 @@
|
|||||||
//! Types and traits for decoding values from the database.
|
//! Types and traits for decoding values from the database.
|
||||||
|
|
||||||
use crate::database::HasRawValue;
|
use crate::database::{Database, HasRawValue};
|
||||||
|
|
||||||
/// Decode a single value from the database.
|
/// A type that can be decoded from the database.
|
||||||
pub trait Decode<'de, DB>
|
pub trait Decode<'de, DB>
|
||||||
where
|
where
|
||||||
Self: Sized + 'de,
|
Self: Sized + 'de,
|
||||||
@ -10,3 +10,14 @@ where
|
|||||||
{
|
{
|
||||||
fn decode(value: DB::RawValue) -> crate::Result<Self>;
|
fn decode(value: DB::RawValue) -> crate::Result<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type that can be decoded without borrowing from the connection.
|
||||||
|
pub trait DecodeOwned<DB: Database>: for<'de> Decode<'de, DB> {}
|
||||||
|
|
||||||
|
impl<DB, T> DecodeOwned<DB> for T
|
||||||
|
where
|
||||||
|
DB: Database,
|
||||||
|
T: 'static,
|
||||||
|
T: for<'de> Decode<'de, DB>,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user