mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +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.
|
||||
|
||||
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>
|
||||
where
|
||||
Self: Sized + 'de,
|
||||
@ -10,3 +10,14 @@ where
|
||||
{
|
||||
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