#[non_exhaustive]pub enum SqlResult<'a> {
String(Option<&'a [u8]>),
Real(Option<f64>),
Int(Option<i64>),
Decimal(Option<&'a str>),
}Expand description
A possible SQL result consisting of a type and nullable value
This enum is similar to SqlType, but actually contains the object.
It is of note that both SqlResult::String contains a u8 slice rather
than a representation like &str. This is because there is no guarantee
that the data is utf8. Use SqlResult::as_string() if you need an easy
way to get a &str.
This enum is labeled non_exhaustive to leave room for future types and
coercion options.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
String(Option<&'a [u8]>)
A string result
Real(Option<f64>)
A floating point result
Int(Option<i64>)
A nullable integer
Decimal(Option<&'a str>)
This is a string that is to be represented as a decimal
Implementations§
Source§impl<'a> SqlResult<'a>
impl<'a> SqlResult<'a>
Sourcepub fn display_name(&self) -> &'static str
pub fn display_name(&self) -> &'static str
Small helper function to get a displayable type name.
Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Check if this argument is an string type, even if it may be null
Sourcepub fn is_decimal(&self) -> bool
pub fn is_decimal(&self) -> bool
Check if this argument is an decimal type, even if it may be null
Sourcepub fn as_int(&self) -> Option<i64>
pub fn as_int(&self) -> Option<i64>
Return this type as an integer if possible
This will exist if the variant is SqlResult::Int, and it contains a
value.
These as_* methods are helpful to quickly obtain a value when you
expect it to be of a specific type and present.
Sourcepub fn as_real(&'a self) -> Option<f64>
pub fn as_real(&'a self) -> Option<f64>
Return this type as a float if possible
This will exist if the variant is SqlResult::Real, and it contains a
value. See SqlResult::as_int() for further details on as_* methods
Sourcepub fn as_string(&'a self) -> Option<&'a str>
pub fn as_string(&'a self) -> Option<&'a str>
Return this type as a string if possible
This will exist if the variant is SqlResult::String, or
SqlResult::Decimal, and it contains a value, and the string can
successfully be converted to utf8 (using str::from_utf8). It does
not distinguish among errors (wrong type, None value, or invalid utf8)
- use pattern matching if you need that.
See SqlResult::as_int() for further details on as_* methods
Sourcepub fn as_bytes(&'a self) -> Option<&'a [u8]>
pub fn as_bytes(&'a self) -> Option<&'a [u8]>
Return this type as a byte slice if possible
This will exist if the variant is SqlResult::String, or
SqlResult::Decimal. See SqlResult::as_int() for further details
on as_* methods