Arcify unknown types

This commit is contained in:
Steven Fackler 2016-01-02 20:07:33 -08:00
parent 277e2b6a48
commit 54735d9f4f
2 changed files with 28 additions and 13 deletions

View File

@ -373,7 +373,7 @@ struct InnerConnection {
notice_handler: Box<HandleNotice>, notice_handler: Box<HandleNotice>,
notifications: VecDeque<Notification>, notifications: VecDeque<Notification>,
cancel_data: CancelData, cancel_data: CancelData,
unknown_types: HashMap<Oid, Type>, unknown_types: HashMap<Oid, Other>,
cached_statements: HashMap<String, CachedStatement>, cached_statements: HashMap<String, CachedStatement>,
parameters: HashMap<String, String>, parameters: HashMap<String, String>,
next_stmt_id: u32, next_stmt_id: u32,
@ -715,7 +715,7 @@ impl InnerConnection {
} }
if let Some(ty) = self.unknown_types.get(&oid) { if let Some(ty) = self.unknown_types.get(&oid) {
return Ok(ty.clone()); return Ok(Type::Other(ty.clone()));
} }
// Ew @ doing this manually :( // 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()); self.unknown_types.insert(oid, type_.clone());
Ok(type_) Ok(Type::Other(type_))
} }
fn is_desynchronized(&self) -> bool { fn is_desynchronized(&self) -> bool {

View File

@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::error; use std::error;
use std::fmt; use std::fmt;
use std::io::prelude::*; use std::io::prelude::*;
use std::sync::Arc;
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian}; use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
pub use self::slice::Slice; pub use self::slice::Slice;
@ -128,7 +129,7 @@ macro_rules! make_postgres_type {
$variant, $variant,
)+ )+
/// An unknown type. /// An unknown type.
Other(Box<Other>), Other(Other),
} }
impl fmt::Debug for Type { impl fmt::Debug for Type {
@ -520,8 +521,22 @@ make_postgres_type! {
} }
/// Information about an unknown type. /// Information about an unknown type.
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone)]
pub struct Other { pub struct Other(Arc<OtherInner>);
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, name: String,
oid: Oid, oid: Oid,
kind: Kind, kind: Kind,
@ -530,34 +545,34 @@ pub struct Other {
impl OtherNew for Other { impl OtherNew for Other {
fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other { fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other {
Other { Other(Arc::new(OtherInner {
name: name, name: name,
oid: oid, oid: oid,
kind: kind, kind: kind,
schema: schema, schema: schema,
} }))
} }
} }
impl Other { impl Other {
/// The name of the type. /// The name of the type.
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
&self.name &self.0.name
} }
/// The OID of this type. /// The OID of this type.
pub fn oid(&self) -> Oid { pub fn oid(&self) -> Oid {
self.oid self.0.oid
} }
/// The kind of this type. /// The kind of this type.
pub fn kind(&self) -> &Kind { pub fn kind(&self) -> &Kind {
&self.kind &self.0.kind
} }
/// The schema of this type. /// The schema of this type.
pub fn schema(&self) -> &str { pub fn schema(&self) -> &str {
&self.schema &self.0.schema
} }
} }