From c34fa5ccd893a1e49e4bdd0c4484dbb22a7e2ff9 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 27 Dec 2015 13:47:32 -0700 Subject: [PATCH] Implement Debug for SessionInfo and Display for Type --- src/types/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/types/mod.rs b/src/types/mod.rs index d8bf3a72..61b4ce38 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -90,6 +90,14 @@ impl<'a> SessionInfo<'a> { } } +impl<'a> fmt::Debug for SessionInfo<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("SessionInfo") + .field("parameters", &self.conn.parameters) + .finish() + } +} + /// A Postgres OID. pub type Oid = u32; @@ -137,6 +145,16 @@ macro_rules! make_postgres_type { } } + impl fmt::Display for Type { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.schema() { + "public" | "pg_catalog" => {} + schema => try!(write!(fmt, "{}.", schema)), + } + fmt.write_str(self.name()) + } + } + impl Type { /// Returns the `Type` corresponding to the provided `Oid` if it /// corresponds to a built-in type. @@ -571,7 +589,7 @@ pub struct WrongType(Type); impl fmt::Display for WrongType { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "cannot convert to or from a Postgres value of type {:?}", self.0) + write!(fmt, "cannot convert to or from a Postgres value of type `{}`", self.0) } }