Trait mysql::prelude::FromValue[][src]

pub trait FromValue {
    type Intermediate: ConvIr<Self>;
    fn from_value(v: Value) -> Self { ... }
fn from_value_opt(v: Value) -> Result<Self, FromValueError> { ... }
fn get_intermediate(v: Value) -> Result<Self::Intermediate, FromValueError> { ... } }

Implement this trait to convert value to something.

FromRow requires ability to cheaply rollback FromValue conversion. This ability is provided via Intermediate associated type.

Example implementation:

This example is not tested
#[derive(Debug)]
pub struct StringIr {
    bytes: Vec<u8>,
}

impl ConvIr<String> for StringIr {
    fn new(v: Value) -> MyResult<StringIr> {
        match v {
            Value::Bytes(bytes) => match from_utf8(&*bytes) {
                Ok(_) => Ok(StringIr { bytes: bytes }),
                Err(_) => Err(Error::FromValueError(Value::Bytes(bytes))),
            },
            v => Err(Error::FromValueError(v)),
        }
    }
    fn commit(self) -> String {
        unsafe { String::from_utf8_unchecked(self.bytes) }
    }
    fn rollback(self) -> Value {
        Value::Bytes(self.bytes)
    }
}

impl FromValue for String {
    type Intermediate = StringIr;
}

Associated Types

Provided Methods

Will panic if could not convert v to Self.

Will return Err(Error::FromValueError(v)) if could not convert v to Self.

Will return Err(Error::FromValueError(v)) if v is not convertible to Self.

Implementations on Foreign Types

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

impl FromValue for i8
[src]

impl FromValue for isize
[src]

impl FromValue for u16
[src]

impl FromValue for i64
[src]

impl FromValue for Duration
[src]

impl FromValue for u64
[src]

impl FromValue for String
[src]

impl FromValue for Value
[src]

impl FromValue for f32
[src]

impl FromValue for bool
[src]

impl FromValue for usize
[src]

impl FromValue for Vec<u8>
[src]

Important traits for Vec<u8>

impl FromValue for u8
[src]

impl FromValue for i32
[src]

impl FromValue for f64
[src]

impl FromValue for u32
[src]

impl FromValue for i16
[src]

Implementors