Skip to content

Commit c34fa5c

Browse files
committed
Implement Debug for SessionInfo and Display for Type
1 parent 1188eb1 commit c34fa5c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/types/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ impl<'a> SessionInfo<'a> {
9090
}
9191
}
9292

93+
impl<'a> fmt::Debug for SessionInfo<'a> {
94+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
95+
fmt.debug_struct("SessionInfo")
96+
.field("parameters", &self.conn.parameters)
97+
.finish()
98+
}
99+
}
100+
93101
/// A Postgres OID.
94102
pub type Oid = u32;
95103

@@ -137,6 +145,16 @@ macro_rules! make_postgres_type {
137145
}
138146
}
139147

148+
impl fmt::Display for Type {
149+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
150+
match self.schema() {
151+
"public" | "pg_catalog" => {}
152+
schema => try!(write!(fmt, "{}.", schema)),
153+
}
154+
fmt.write_str(self.name())
155+
}
156+
}
157+
140158
impl Type {
141159
/// Returns the `Type` corresponding to the provided `Oid` if it
142160
/// corresponds to a built-in type.
@@ -571,7 +589,7 @@ pub struct WrongType(Type);
571589

572590
impl fmt::Display for WrongType {
573591
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
574-
write!(fmt, "cannot convert to or from a Postgres value of type {:?}", self.0)
592+
write!(fmt, "cannot convert to or from a Postgres value of type `{}`", self.0)
575593
}
576594
}
577595

0 commit comments

Comments
 (0)