use crate::mock_db; use crate::mock_db::{MValue, ResultSet}; use serde_db::de::{ ConversionError, DbValue, DbValueInto, DeserializableResultSet, DeserializationError, }; use std::{i16, i32, i8, u16, u32, u8}; fn not_implemented(s: &'static str) -> ConversionError { ConversionError::ValueType(format!("{} not implemented", s)) } impl DbValue for MValue { fn is_null(&self) -> bool { if let MValue::Null = *self { true } else { false } } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { match self { MValue::Short(i) => Ok(i), mv => Err(ConversionError::ValueType(format!( "DbValueInto not implemented for {:?}", mv ))), } } } impl DbValueInto for MValue { fn try_into(self) -> Result { match self { MValue::Short(i) => Ok(i32::from(i)), mv => Err(ConversionError::ValueType(format!( "DbValueInto not implemented for {:?}", mv ))), } } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { Err(not_implemented("DbValueInto")) } } impl DbValueInto for MValue { fn try_into(self) -> Result { match self { MValue::Double(f) => Ok(f), mv => Err(ConversionError::ValueType(format!( "DbValueInto not implemented for {:?}", mv ))), } } } impl DbValueInto for MValue { fn try_into(self) -> Result { trace!("try_into -> String"); match self { MValue::String(s) => Ok(s), MValue::Timestamp(ts) => Ok(ts.to_string()), MValue::Double(f) => Ok(f.to_string()), mv => Err(ConversionError::ValueType(format!( "DbValueInto not implemented for {:?}", mv ))), } } } impl DbValueInto> for MValue { fn try_into(self) -> Result, ConversionError> { Err(not_implemented("DbValueInto>")) } } impl DeserializableResultSet for ResultSet { type Error = mock_db::Error; type Row = mock_db::Row; fn has_multiple_rows(&mut self) -> Result { Ok(self.has_multiple_rows()) } fn next(&mut self) -> Result, DeserializationError> { Ok(self.next()) } fn number_of_fields(&self) -> usize { self.number_of_fields() } fn field_name(&self, i: usize) -> Option<&str> { self.field_name(i) } } impl From for mock_db::Error { fn from(e: DeserializationError) -> mock_db::Error { mock_db::Error::DESERIALIZATION(e) } }