Trait mysql::prelude::FromValue
[−]
[src]
pub trait FromValue: Sized { type Intermediate: ConvIr<Self>; fn from_value(v: Value) -> Self { ... } fn from_value_opt(v: Value) -> MyResult<Self> { ... } fn get_intermediate(v: Value) -> MyResult<Self::Intermediate> { ... } }
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:
#[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
type Intermediate: ConvIr<Self>
Provided Methods
fn from_value(v: Value) -> Self
Will panic if could not convert v to Self.
fn from_value_opt(v: Value) -> MyResult<Self>
Will return Err(Error::FromValueError(v)) if could not convert v to Self.
fn get_intermediate(v: Value) -> MyResult<Self::Intermediate>
Will return Err(Error::FromValueError(v)) if v is not convertible to Self.
Implementors
impl<T> FromValue for Option<T> where
T: FromValue,impl FromValue for Valueimpl FromValue for NaiveDateTimeimpl FromValue for NaiveDateimpl FromValue for NaiveTimeimpl FromValue for Timespecimpl FromValue for std::time::duration::Durationimpl FromValue for time::duration::Durationimpl FromValue for Stringimpl FromValue for Vec<u8>impl FromValue for boolimpl FromValue for i64impl FromValue for u64impl FromValue for f32impl FromValue for f64impl FromValue for i8impl FromValue for u8impl FromValue for i16impl FromValue for u16impl FromValue for i32impl FromValue for u32impl FromValue for isizeimpl FromValue for usizeimpl FromValue for Uuidimpl<T: DeserializeOwned> FromValue for Deserialized<T>impl FromValue for Json