Add DecodeOwned to help with trait bounds on owned data

This commit is contained in:
Ryan Leckey 2020-03-20 19:54:44 -07:00
parent f562e919b7
commit 24d62dd464

View File

@ -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>,
{
}