Enum SqlResult

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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>

Source

pub fn display_name(&self) -> &'static str

Small helper function to get a displayable type name.

Source

pub fn is_int(&self) -> bool

Check if this argument is an integer type, even if it may be null

Source

pub fn is_real(&self) -> bool

Check if this argument is an real type, even if it may be null

Source

pub fn is_string(&self) -> bool

Check if this argument is an string type, even if it may be null

Source

pub fn is_decimal(&self) -> bool

Check if this argument is an decimal type, even if it may be null

Source

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.

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl<'a> Clone for SqlResult<'a>

Source§

fn clone(&self) -> SqlResult<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for SqlResult<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for SqlResult<'a>

Source§

fn eq(&self, other: &SqlResult<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&SqlResult<'_>> for SqlType

Source§

fn try_from(tag: &SqlResult<'_>) -> Result<Self, Self::Error>

Create an SqlType from an SqlResult

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

impl<'a> StructuralPartialEq for SqlResult<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for SqlResult<'a>

§

impl<'a> RefUnwindSafe for SqlResult<'a>

§

impl<'a> Send for SqlResult<'a>

§

impl<'a> Sync for SqlResult<'a>

§

impl<'a> Unpin for SqlResult<'a>

§

impl<'a> UnwindSafe for SqlResult<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.