sqlx_core/any/
type_info.rs

1use std::fmt::{self, Display, Formatter};
2
3use crate::type_info::TypeInfo;
4
5#[cfg(feature = "postgres")]
6use crate::postgres::PgTypeInfo;
7
8#[cfg(feature = "mysql")]
9use crate::mysql::MySqlTypeInfo;
10
11#[cfg(feature = "sqlite")]
12use crate::sqlite::SqliteTypeInfo;
13
14#[cfg(feature = "mssql")]
15use crate::mssql::MssqlTypeInfo;
16
17#[derive(Debug, Clone, PartialEq)]
18pub struct AnyTypeInfo(pub(crate) AnyTypeInfoKind);
19
20#[derive(Debug, Clone, PartialEq)]
21pub(crate) enum AnyTypeInfoKind {
22    #[cfg(feature = "postgres")]
23    Postgres(PgTypeInfo),
24
25    #[cfg(feature = "mysql")]
26    MySql(MySqlTypeInfo),
27
28    #[cfg(feature = "sqlite")]
29    Sqlite(SqliteTypeInfo),
30
31    #[cfg(feature = "mssql")]
32    Mssql(MssqlTypeInfo),
33}
34
35impl TypeInfo for AnyTypeInfo {
36    fn is_null(&self) -> bool {
37        match &self.0 {
38            #[cfg(feature = "postgres")]
39            AnyTypeInfoKind::Postgres(ty) => ty.is_null(),
40
41            #[cfg(feature = "mysql")]
42            AnyTypeInfoKind::MySql(ty) => ty.is_null(),
43
44            #[cfg(feature = "sqlite")]
45            AnyTypeInfoKind::Sqlite(ty) => ty.is_null(),
46
47            #[cfg(feature = "mssql")]
48            AnyTypeInfoKind::Mssql(ty) => ty.is_null(),
49        }
50    }
51
52    fn name(&self) -> &str {
53        match &self.0 {
54            #[cfg(feature = "postgres")]
55            AnyTypeInfoKind::Postgres(ty) => ty.name(),
56
57            #[cfg(feature = "mysql")]
58            AnyTypeInfoKind::MySql(ty) => ty.name(),
59
60            #[cfg(feature = "sqlite")]
61            AnyTypeInfoKind::Sqlite(ty) => ty.name(),
62
63            #[cfg(feature = "mssql")]
64            AnyTypeInfoKind::Mssql(ty) => ty.name(),
65        }
66    }
67}
68
69impl Display for AnyTypeInfo {
70    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
71        match &self.0 {
72            #[cfg(feature = "postgres")]
73            AnyTypeInfoKind::Postgres(ty) => ty.fmt(f),
74
75            #[cfg(feature = "mysql")]
76            AnyTypeInfoKind::MySql(ty) => ty.fmt(f),
77
78            #[cfg(feature = "sqlite")]
79            AnyTypeInfoKind::Sqlite(ty) => ty.fmt(f),
80
81            #[cfg(feature = "mssql")]
82            AnyTypeInfoKind::Mssql(ty) => ty.fmt(f),
83        }
84    }
85}