Simplify InvalidType

This commit is contained in:
gwenn
2016-05-30 21:20:07 +02:00
parent fb19e718cf
commit 91dc30b04d
6 changed files with 12 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ impl FromSql for f64 {
match value {
ValueRef::Integer(i) => Ok(i as f64),
ValueRef::Real(f) => Ok(f),
_ => Err(Error::InvalidType(value.data_type())),
_ => Err(Error::InvalidType),
}
}
}

View File

@@ -23,7 +23,7 @@ impl FromSql for Value {
match value {
ValueRef::Text(ref s) => serde_json::from_str(s),
ValueRef::Blob(ref b) => serde_json::from_slice(b),
_ => return Err(Error::InvalidType(value.data_type())),
_ => return Err(Error::InvalidType),
}
.map_err(|err| Error::FromSqlConversionFailure(Box::new(err)))
}

View File

@@ -38,7 +38,7 @@ impl<'a> ValueRef<'a> {
pub fn as_i64(&self) -> Result<i64> {
match *self {
ValueRef::Integer(i) => Ok(i),
_ => Err(Error::InvalidType(self.data_type())),
_ => Err(Error::InvalidType),
}
}
@@ -47,7 +47,7 @@ impl<'a> ValueRef<'a> {
pub fn as_f64(&self) -> Result<f64> {
match *self {
ValueRef::Real(f) => Ok(f),
_ => Err(Error::InvalidType(self.data_type())),
_ => Err(Error::InvalidType),
}
}
@@ -56,7 +56,7 @@ impl<'a> ValueRef<'a> {
pub fn as_str(&self) -> Result<&str> {
match *self {
ValueRef::Text(ref t) => Ok(t),
_ => Err(Error::InvalidType(self.data_type())),
_ => Err(Error::InvalidType),
}
}
@@ -65,7 +65,7 @@ impl<'a> ValueRef<'a> {
pub fn as_blob(&self) -> Result<&[u8]> {
match *self {
ValueRef::Blob(ref b) => Ok(b),
_ => Err(Error::InvalidType(self.data_type())),
_ => Err(Error::InvalidType),
}
}
}