pub trait FromSql<'a>where
Self: Sized + 'a,{
fn from_sql(value: &'a ColumnData<'static>) -> Result<Option<Self>>;
}
Expand description
A conversion trait from a TDS type by-reference.
A FromSql
implementation for a Rust type is needed for using it as a
return parameter from Row#get
or Row#try_get
methods. The following
Rust types are already implemented to match the given server types:
Rust type | Server type |
---|---|
u8 | tinyint |
i16 | smallint |
i32 | int |
i64 | bigint |
f32 | float(24) |
f64 | float(53) |
bool | bit |
String /&str | nvarchar /varchar /nchar /char /ntext /text |
Vec<u8> /&[u8] | binary /varbinary /image |
Uuid | uniqueidentifier |
Numeric | numeric /decimal |
Decimal (with feature flag rust_decimal ) | numeric /decimal |
XmlData | xml |
NaiveDateTime (with feature flag chrono ) | datetime /datetime2 /smalldatetime |
NaiveDate (with feature flag chrono ) | date |
NaiveTime (with feature flag chrono ) | time |
DateTime (with feature flag chrono ) | datetimeoffset |
See the time
module for more information about the date and time structs.
Required Methods
sourcefn from_sql(value: &'a ColumnData<'static>) -> Result<Option<Self>>
fn from_sql(value: &'a ColumnData<'static>) -> Result<Option<Self>>
Returns the value, None
being a null value, copying the value.
Implementations on Foreign Types
sourceimpl<'a> FromSql<'a> for bool
impl<'a> FromSql<'a> for bool
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for u8
impl<'a> FromSql<'a> for u8
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for i16
impl<'a> FromSql<'a> for i16
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for i32
impl<'a> FromSql<'a> for i32
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for i64
impl<'a> FromSql<'a> for i64
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for f32
impl<'a> FromSql<'a> for f32
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for f64
impl<'a> FromSql<'a> for f64
fn from_sql(data: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for &'a str
impl<'a> FromSql<'a> for &'a str
fn from_sql(value: &'a ColumnData<'static>) -> Result<Option<Self>>
sourceimpl<'a> FromSql<'a> for &'a [u8]
impl<'a> FromSql<'a> for &'a [u8]
fn from_sql(value: &'a ColumnData<'static>) -> Result<Option<Self>>
Implementors
impl<'a> FromSql<'a> for &'a XmlData
impl<'a> FromSql<'a> for BigDecimal
impl<'a> FromSql<'a> for Decimal
impl<'a> FromSql<'a> for Numeric
impl<'a> FromSql<'a> for Uuid
impl<'a> FromSql<'a> for DateTime<FixedOffset>
Available on crate feature
chrono
only.impl<'a> FromSql<'a> for DateTime<Utc>
Available on crate feature
chrono
only.impl<'a> FromSql<'a> for NaiveDate
Available on crate feature
chrono
only.impl<'a> FromSql<'a> for NaiveDateTime
Available on crate feature
chrono
only.impl<'a> FromSql<'a> for NaiveTime
Available on crate feature
chrono
only.impl<'a> FromSql<'a> for Date
Available on crate feature
time
only.impl<'a> FromSql<'a> for OffsetDateTime
Available on crate feature
time
only.impl<'a> FromSql<'a> for PrimitiveDateTime
Available on crate feature
time
only.impl<'a> FromSql<'a> for Time
Available on crate feature
time
only.