Return references from Type::kind

This commit is contained in:
Steven Fackler
2015-02-17 23:49:11 -08:00
parent fdc41dd72b
commit 89f00b38e4
2 changed files with 8 additions and 5 deletions

View File

@@ -253,12 +253,15 @@ macro_rules! make_postgres_type {
}
/// The kind of this type
pub fn kind(&self) -> Kind {
pub fn kind(&self) -> &Kind {
match *self {
$(
Type::$variant => $kind,
Type::$variant => {
const V: &'static Kind = &$kind;
V
}
)+
Type::Unknown(ref u) => u.kind().clone(),
Type::Unknown(ref u) => u.kind(),
}
}
}

View File

@@ -6,7 +6,7 @@ use {Type, ToSql, Result, Error, Kind};
///
/// `Slice`'s `ToSql` implementation maps the slice to a one-dimensional
/// Postgres array of the relevant type. This is particularly useful with the
/// `ANY` operator to match a column against multiple values without having
/// `ANY` function to match a column against multiple values without having
/// to dynamically construct the query string.
///
/// # Examples
@@ -27,7 +27,7 @@ pub struct Slice<'a, T: 'a + ToSql>(pub &'a [T]);
impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
let member_type = match ty.kind() {
Kind::Array(member) => member,
&Kind::Array(ref member) => member,
_ => return Err(Error::WrongType(ty.clone())),
};