Trait mysql_common::row::convert::FromRow

source ·
pub trait FromRow {
    // Required method
    fn from_row_opt(row: Row) -> Result<Self, FromRowError>
       where Self: Sized;

    // Provided method
    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) -> Self
where Self: Sized,

Implementations on Foreign Types§

source§

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

source§

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

source§

impl<T1, T2, T3> FromRow for (T1, T2, T3)

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

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)

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)

Implementors§

source§

impl FromRow for Row

source§

impl<T> FromRow for T
where T: FromValue,