[][src]Trait mysql_async::prelude::FromRow

pub trait FromRow {
    fn from_row_opt(row: Row) -> Result<Self, FromRowError>;

    fn from_row(row: Row) -> Self { ... }
}

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.

This example is not tested
// 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

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

Loading content...

Provided methods

fn from_row(row: Row) -> Self

Loading content...

Implementations on Foreign Types

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
[src]

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
[src]

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,
    T10: FromValue,
    T11: FromValue,
    T2: FromValue,
    T3: FromValue,
    T4: FromValue,
    T5: FromValue,
    T6: FromValue,
    T7: FromValue,
    T8: FromValue,
    T9: FromValue
[src]

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

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

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
[src]

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

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

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,
    T10: FromValue,
    T11: FromValue,
    T12: FromValue,
    T2: FromValue,
    T3: FromValue,
    T4: FromValue,
    T5: FromValue,
    T6: FromValue,
    T7: FromValue,
    T8: FromValue,
    T9: FromValue
[src]

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
[src]

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

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,
    T10: FromValue,
    T2: FromValue,
    T3: FromValue,
    T4: FromValue,
    T5: FromValue,
    T6: FromValue,
    T7: FromValue,
    T8: FromValue,
    T9: FromValue
[src]

Loading content...

Implementors

impl FromRow for Row[src]

impl<T> FromRow for T where
    T: FromValue
[src]

Loading content...