Trait mysql::prelude::FromRow

source ·
pub trait FromRow {
    fn from_row_opt(row: Row) -> Result<Self, FromRowError>
where
Self: Sized
; fn from_row(row: Row) -> Self
where
Self: Sized
, { ... } }
Expand description

Trait to convert Row into a tuple of FromValue implementors up to arity 12.

This trait is convenient way to convert mysql row to a tuple or rust types and relies on FromValue trait, i.e. calling from_row::<(T, U)>(row) is similar to calling (T::from_value(column_1), U::from_value(column_2)).

Note that conversion will always fail if any of columns was taken using Row::take method.

Conversion of individual columns of a row may fail. In this case from_row will panic, and from_row_opt will roll back conversion and return original row.

Concrete types of columns in a row is usually known to a programmer so from_value should never panic if types specified correctly. This means that column which holds NULL should correspond to a type wrapped in Option, String is used only with column which hold correct utf8, size and signedness of a numeric type should match to a value stored in a column and so on.

// Consider columns in the row is: Bytes(<some binary data>), NULL and Int(1024)
from_row::<(String, u8, u8)>(row) // this will panic because of invalid utf8 in first column.
from_row::<(Vec<u8>, u8, u8)>(row) // this will panic because of a NULL in second column.
from_row::<(Vec<u8>, Option<u8>, u8)>(row) // this will panic because 1024 does not fit in u8.
from_row::<(Vec<u8>)>(row) // this will panic because number of columns != arity of a tuple.
from_row::<(Vec<u8>, Option<u8>, u16, Option<u8>)>(row) // same reason of panic as previous.

from_row::<(Vec<u8>, Option<u8>, u16)>(row) // this'll work and return (vec![..], None, 1024u16)

Required Methods§

source

fn from_row_opt(row: Row) -> Result<Self, FromRowError>where
Self: Sized,

Provided Methods§

source

fn from_row(row: Row) -> Selfwhere
Self: Sized,

Implementations on Foreign Types§

source§

impl<T1, T2, T3, T4, T5, T6, T7, T8> FromRow for (T1, T2, T3, T4, T5, T6, T7, T8)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,
T8: FromValue,

source§

impl<H, T> FromRow for HCons<H, T>where
H: FromValue,
T: FromRow + HlistFromRow + HList,

source§

fn from_row_opt(row: Row) -> Result<HCons<H, T>, FromRowError>where
HCons<H, T>: Sized,

source§

impl<T1, T2, T3> FromRow for (T1, T2, T3)where
T1: FromValue,
T2: FromValue,
T3: FromValue,

source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> FromRow for (T1, T2, T3, T4, T5, T6, T7, T8, T9)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,
T8: FromValue,
T9: FromValue,

source§

impl<T1, T2, T3, T4, T5> FromRow for (T1, T2, T3, T4, T5)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,

source§

impl<T1, T2> FromRow for (T1, T2)where
T1: FromValue,
T2: FromValue,

source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> FromRow for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,
T8: FromValue,
T9: FromValue,
T10: FromValue,

source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> FromRow for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,
T8: FromValue,
T9: FromValue,
T10: FromValue,
T11: FromValue,
T12: FromValue,

source§

impl<T1, T2, T3, T4, T5, T6, T7> FromRow for (T1, T2, T3, T4, T5, T6, T7)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,

source§

impl<T1, T2, T3, T4, T5, T6> FromRow for (T1, T2, T3, T4, T5, T6)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,

source§

impl<T1> FromRow for (T1,)where
T1: FromValue,

source§

impl<T1, T2, T3, T4> FromRow for (T1, T2, T3, T4)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,

source§

impl FromRow for HNil

source§

fn from_row_opt(row: Row) -> Result<HNil, FromRowError>where
HNil: Sized,

source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> FromRow for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)where
T1: FromValue,
T2: FromValue,
T3: FromValue,
T4: FromValue,
T5: FromValue,
T6: FromValue,
T7: FromValue,
T8: FromValue,
T9: FromValue,
T10: FromValue,
T11: FromValue,

Implementors§

source§

impl FromRow for Row

source§

impl<T> FromRow for Twhere
T: FromValue,