diff --git a/src/lib.rs b/src/lib.rs index 029d2112..1bf0e13d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,7 +373,7 @@ struct InnerConnection { notice_handler: Box, notifications: VecDeque, cancel_data: CancelData, - unknown_types: HashMap, + unknown_types: HashMap, cached_statements: HashMap, parameters: HashMap, next_stmt_id: u32, @@ -715,7 +715,7 @@ impl InnerConnection { } if let Some(ty) = self.unknown_types.get(&oid) { - return Ok(ty.clone()); + return Ok(Type::Other(ty.clone())); } // Ew @ doing this manually :( @@ -787,9 +787,9 @@ impl InnerConnection { } }; - let type_ = Type::Other(Box::new(Other::new(name, oid, kind, schema))); + let type_ = Other::new(name, oid, kind, schema); self.unknown_types.insert(oid, type_.clone()); - Ok(type_) + Ok(Type::Other(type_)) } fn is_desynchronized(&self) -> bool { diff --git a/src/types/mod.rs b/src/types/mod.rs index 8743eadb..91b02a29 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use std::error; use std::fmt; use std::io::prelude::*; +use std::sync::Arc; use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian}; pub use self::slice::Slice; @@ -128,7 +129,7 @@ macro_rules! make_postgres_type { $variant, )+ /// An unknown type. - Other(Box), + Other(Other), } impl fmt::Debug for Type { @@ -520,8 +521,22 @@ make_postgres_type! { } /// Information about an unknown type. -#[derive(PartialEq, Eq, Clone, Debug)] -pub struct Other { +#[derive(PartialEq, Eq, Clone)] +pub struct Other(Arc); + +impl fmt::Debug for Other { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("Other") + .field("name", &self.0.name) + .field("oid", &self.0.oid) + .field("kind", &self.0.kind) + .field("schema", &self.0.schema) + .finish() + } +} + +#[derive(PartialEq, Eq)] +struct OtherInner { name: String, oid: Oid, kind: Kind, @@ -530,34 +545,34 @@ pub struct Other { impl OtherNew for Other { fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other { - Other { + Other(Arc::new(OtherInner { name: name, oid: oid, kind: kind, schema: schema, - } + })) } } impl Other { /// The name of the type. pub fn name(&self) -> &str { - &self.name + &self.0.name } /// The OID of this type. pub fn oid(&self) -> Oid { - self.oid + self.0.oid } /// The kind of this type. pub fn kind(&self) -> &Kind { - &self.kind + &self.0.kind } /// The schema of this type. pub fn schema(&self) -> &str { - &self.schema + &self.0.schema } }