Skip to content

Commit f72bc43

Browse files
committed
Hide Type constructor
1 parent bfe7edf commit f72bc43

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl InnerConnection {
797797
}
798798

799799
fn get_type(&mut self, oid: Oid) -> Result<Type> {
800-
if let Some(ty) = Type::from_oid(oid) {
800+
if let Some(ty) = Type::new(oid) {
801801
return Ok(ty);
802802
}
803803

@@ -2151,3 +2151,7 @@ trait DbErrorNew {
21512151
fn new_connect<T>(fields: Vec<(u8, String)>) -> result::Result<T, ConnectError>;
21522152
fn new<T>(fields: Vec<(u8, String)>) -> Result<T>;
21532153
}
2154+
2155+
trait TypeNew {
2156+
fn new(oid: Oid) -> Option<Type>;
2157+
}

src/types/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::prelude::*;
77
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
88

99
pub use self::slice::Slice;
10-
use {Result, SessionInfoNew, InnerConnection, OtherNew};
10+
use {Result, SessionInfoNew, InnerConnection, OtherNew, TypeNew};
1111
use error::Error;
1212
use util;
1313

@@ -120,17 +120,17 @@ macro_rules! make_postgres_type {
120120
}
121121
}
122122

123-
impl Type {
124-
/// Creates a `Type` from an OID.
125-
///
126-
/// If the OID is unknown, `None` is returned.
127-
pub fn from_oid(oid: Oid) -> Option<Type> {
123+
impl TypeNew for Type {
124+
fn new(oid: Oid) -> Option<Type> {
128125
match oid {
129126
$(as_pat!($oid) => Some(Type::$variant),)+
130127
_ => None
131128
}
132129
}
133130

131+
}
132+
133+
impl Type {
134134
/// Returns the OID of the `Type`.
135135
pub fn oid(&self) -> Oid {
136136
match *self {

src/types/slice.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use types::{Type, ToSql, Kind, IsNull, SessionInfo};
1616
///
1717
/// ```rust,no_run
1818
/// # fn foo() -> postgres::Result<()> {
19-
/// # use postgres::{Connection, SslMode, Slice};
19+
/// # use postgres::{Connection, SslMode};
20+
/// # use postgres::types::Slice;
2021
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
2122
/// let values = &[1i32, 2, 3, 4, 5, 6];
2223
/// let stmt = try!(conn.prepare("SELECT * FROM foo WHERE id = ANY($1)"));
@@ -45,7 +46,7 @@ impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
4546

4647
try!(w.write_i32::<BigEndian>(1)); // number of dimensions
4748
try!(w.write_i32::<BigEndian>(1)); // has nulls
48-
try!(w.write_u32::<BigEndian>(member_type.to_oid()));
49+
try!(w.write_u32::<BigEndian>(member_type.oid()));
4950

5051
try!(w.write_i32::<BigEndian>(self.0.len() as i32));
5152
try!(w.write_i32::<BigEndian>(0)); // index offset

tests/types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::f32;
33
use std::f64;
44
use std::fmt;
55

6-
use postgres::{Connection, SslMode, Slice};
6+
use postgres::{Connection, SslMode};
77
use postgres::error::Error;
8-
use postgres::types::{ToSql, FromSql};
8+
use postgres::types::{ToSql, FromSql, Slice};
99

1010
#[cfg(feature = "uuid")]
1111
mod uuid;

0 commit comments

Comments
 (0)