forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.rs
More file actions
54 lines (46 loc) 路 1.27 KB
/
Copy pathtypes.rs
File metadata and controls
54 lines (46 loc) 路 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Traits linking Rust types to SQL types.
use std::fmt::{Debug, Display};
use crate::database::Database;
#[cfg(feature = "uuid")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid")))]
pub use uuid::Uuid;
#[cfg(feature = "chrono")]
#[cfg_attr(docsrs, doc(cfg(feature = "chrono")))]
pub mod chrono {
pub use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
}
pub trait TypeInfo: Debug + Display + Clone {
/// Compares type information to determine if `other` is compatible at the Rust level
/// with `self`.
fn compatible(&self, other: &Self) -> bool;
}
/// Indicates that a SQL type is supported for a database.
pub trait Type<DB>
where
DB: Database,
{
/// Returns the canonical type information on the database for the type `T`.
fn type_info() -> DB::TypeInfo;
}
// For references to types in Rust, the underlying SQL type information
// is equivalent
impl<T: ?Sized, DB> Type<DB> for &'_ T
where
DB: Database,
T: Type<DB>,
{
fn type_info() -> DB::TypeInfo {
<T as Type<DB>>::type_info()
}
}
// For optional types in Rust, the underlying SQL type information
// is equivalent
impl<T, DB> Type<DB> for Option<T>
where
DB: Database,
T: Type<DB>,
{
fn type_info() -> DB::TypeInfo {
<T as Type<DB>>::type_info()
}
}