Hide Type constructor

This commit is contained in:
Steven Fackler 2015-05-26 21:47:42 -07:00
parent bfe7edfdfe
commit f72bc4303a
4 changed files with 16 additions and 11 deletions

View File

@ -797,7 +797,7 @@ impl InnerConnection {
}
fn get_type(&mut self, oid: Oid) -> Result<Type> {
if let Some(ty) = Type::from_oid(oid) {
if let Some(ty) = Type::new(oid) {
return Ok(ty);
}
@ -2151,3 +2151,7 @@ trait DbErrorNew {
fn new_connect<T>(fields: Vec<(u8, String)>) -> result::Result<T, ConnectError>;
fn new<T>(fields: Vec<(u8, String)>) -> Result<T>;
}
trait TypeNew {
fn new(oid: Oid) -> Option<Type>;
}

View File

@ -7,7 +7,7 @@ use std::io::prelude::*;
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
pub use self::slice::Slice;
use {Result, SessionInfoNew, InnerConnection, OtherNew};
use {Result, SessionInfoNew, InnerConnection, OtherNew, TypeNew};
use error::Error;
use util;
@ -120,17 +120,17 @@ macro_rules! make_postgres_type {
}
}
impl Type {
/// Creates a `Type` from an OID.
///
/// If the OID is unknown, `None` is returned.
pub fn from_oid(oid: Oid) -> Option<Type> {
impl TypeNew for Type {
fn new(oid: Oid) -> Option<Type> {
match oid {
$(as_pat!($oid) => Some(Type::$variant),)+
_ => None
}
}
}
impl Type {
/// Returns the OID of the `Type`.
pub fn oid(&self) -> Oid {
match *self {

View File

@ -16,7 +16,8 @@ use types::{Type, ToSql, Kind, IsNull, SessionInfo};
///
/// ```rust,no_run
/// # fn foo() -> postgres::Result<()> {
/// # use postgres::{Connection, SslMode, Slice};
/// # use postgres::{Connection, SslMode};
/// # use postgres::types::Slice;
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
/// let values = &[1i32, 2, 3, 4, 5, 6];
/// 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> {
try!(w.write_i32::<BigEndian>(1)); // number of dimensions
try!(w.write_i32::<BigEndian>(1)); // has nulls
try!(w.write_u32::<BigEndian>(member_type.to_oid()));
try!(w.write_u32::<BigEndian>(member_type.oid()));
try!(w.write_i32::<BigEndian>(self.0.len() as i32));
try!(w.write_i32::<BigEndian>(0)); // index offset

View File

@ -3,9 +3,9 @@ use std::f32;
use std::f64;
use std::fmt;
use postgres::{Connection, SslMode, Slice};
use postgres::{Connection, SslMode};
use postgres::error::Error;
use postgres::types::{ToSql, FromSql};
use postgres::types::{ToSql, FromSql, Slice};
#[cfg(feature = "uuid")]
mod uuid;