Skip to content

Commit 54735d9

Browse files
committed
Arcify unknown types
1 parent 277e2b6 commit 54735d9

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ struct InnerConnection {
373373
notice_handler: Box<HandleNotice>,
374374
notifications: VecDeque<Notification>,
375375
cancel_data: CancelData,
376-
unknown_types: HashMap<Oid, Type>,
376+
unknown_types: HashMap<Oid, Other>,
377377
cached_statements: HashMap<String, CachedStatement>,
378378
parameters: HashMap<String, String>,
379379
next_stmt_id: u32,
@@ -715,7 +715,7 @@ impl InnerConnection {
715715
}
716716

717717
if let Some(ty) = self.unknown_types.get(&oid) {
718-
return Ok(ty.clone());
718+
return Ok(Type::Other(ty.clone()));
719719
}
720720

721721
// Ew @ doing this manually :(
@@ -787,9 +787,9 @@ impl InnerConnection {
787787
}
788788
};
789789

790-
let type_ = Type::Other(Box::new(Other::new(name, oid, kind, schema)));
790+
let type_ = Other::new(name, oid, kind, schema);
791791
self.unknown_types.insert(oid, type_.clone());
792-
Ok(type_)
792+
Ok(Type::Other(type_))
793793
}
794794

795795
fn is_desynchronized(&self) -> bool {

src/types/mod.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::collections::HashMap;
44
use std::error;
55
use std::fmt;
66
use std::io::prelude::*;
7+
use std::sync::Arc;
78
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
89

910
pub use self::slice::Slice;
@@ -128,7 +129,7 @@ macro_rules! make_postgres_type {
128129
$variant,
129130
)+
130131
/// An unknown type.
131-
Other(Box<Other>),
132+
Other(Other),
132133
}
133134

134135
impl fmt::Debug for Type {
@@ -520,8 +521,22 @@ make_postgres_type! {
520521
}
521522

522523
/// Information about an unknown type.
523-
#[derive(PartialEq, Eq, Clone, Debug)]
524-
pub struct Other {
524+
#[derive(PartialEq, Eq, Clone)]
525+
pub struct Other(Arc<OtherInner>);
526+
527+
impl fmt::Debug for Other {
528+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
529+
fmt.debug_struct("Other")
530+
.field("name", &self.0.name)
531+
.field("oid", &self.0.oid)
532+
.field("kind", &self.0.kind)
533+
.field("schema", &self.0.schema)
534+
.finish()
535+
}
536+
}
537+
538+
#[derive(PartialEq, Eq)]
539+
struct OtherInner {
525540
name: String,
526541
oid: Oid,
527542
kind: Kind,
@@ -530,34 +545,34 @@ pub struct Other {
530545

531546
impl OtherNew for Other {
532547
fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other {
533-
Other {
548+
Other(Arc::new(OtherInner {
534549
name: name,
535550
oid: oid,
536551
kind: kind,
537552
schema: schema,
538-
}
553+
}))
539554
}
540555
}
541556

542557
impl Other {
543558
/// The name of the type.
544559
pub fn name(&self) -> &str {
545-
&self.name
560+
&self.0.name
546561
}
547562

548563
/// The OID of this type.
549564
pub fn oid(&self) -> Oid {
550-
self.oid
565+
self.0.oid
551566
}
552567

553568
/// The kind of this type.
554569
pub fn kind(&self) -> &Kind {
555-
&self.kind
570+
&self.0.kind
556571
}
557572

558573
/// The schema of this type.
559574
pub fn schema(&self) -> &str {
560-
&self.schema
575+
&self.0.schema
561576
}
562577
}
563578

0 commit comments

Comments
 (0)