feat(core): add TypeEncode::compatible

This commit is contained in:
Ryan Leckey 2021-02-18 14:11:35 -08:00
parent ed3e9fdd38
commit 46f314103a
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9

View File

@ -33,11 +33,19 @@ pub trait Type<Db: Database> {
#[allow(clippy::module_name_repetitions)]
pub trait TypeEncode<Db: Database>: Type<Db> + Encode<Db> {
/// Returns the SQL type identifier that best hints to the database
/// at the incoming value for a bind parameter.
/// Returns the canonical SQL type identifier for this Rust type.
#[allow(unused_variables)]
fn type_id(&self, ty: &Db::TypeInfo) -> Db::TypeId;
/// Determines if this Rust type is compatible with the specified SQL type.
///
/// To be compatible, the Rust type must support encoding _and_ decoding
/// from the specified SQL type.
///
fn compatible(&self, ty: &Db::TypeInfo) -> bool {
ty.id() == self.type_id(ty)
}
/// Returns the Rust type name of this.
#[doc(hidden)]
#[inline]