Skip to content

Commit 9523e22

Browse files
committed
Optimize Type's Show and String impls
1 parent 838df94 commit 9523e22

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/types/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const INT8RANGEARRAYOID: Oid = 3927;
184184
macro_rules! make_postgres_type {
185185
($(#[$doc:meta] $oid:ident => $variant:ident: $(member $member:ident)*),+) => (
186186
/// A Postgres type
187-
#[derive(PartialEq, Eq, Clone, Show)]
187+
#[derive(PartialEq, Eq, Clone)]
188188
pub enum Type {
189189
$(
190190
#[$doc]
@@ -199,6 +199,18 @@ macro_rules! make_postgres_type {
199199
}
200200
}
201201

202+
impl fmt::Show for Type {
203+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
204+
let s = match *self {
205+
$(Type::$variant => stringify!($variant),)+
206+
Type::Unknown { ref name, ref oid } => {
207+
return write!(fmt, "Unknown {{ name: {:?}, oid: {:?} }}", name, oid);
208+
}
209+
};
210+
fmt.write_str(s)
211+
}
212+
}
213+
202214
impl fmt::String for Type {
203215
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
204216
let s = match *self {
@@ -207,7 +219,7 @@ macro_rules! make_postgres_type {
207219
)+
208220
Type::Unknown { ref name, .. } => &**name,
209221
};
210-
write!(fmt, "{}", s)
222+
fmt.write_str(s)
211223
}
212224
}
213225

0 commit comments

Comments
 (0)