diff --git a/src/io.rs b/src/io.rs index 08ecbdc9..92f10a96 100644 --- a/src/io.rs +++ b/src/io.rs @@ -4,7 +4,7 @@ use std::io::net::tcp; use std::io::net::pipe; use std::io::{Stream, IoResult}; -use {ConnectParams, SslMode, NoSsl, PreferSsl, RequireSsl, TargetTcp, TargetUnix}; +use {ConnectParams, SslMode, NoSsl, PreferSsl, RequireSsl, ConnectTarget}; use error::{PostgresConnectError, PgConnectStreamError, NoSslSupport, SslError, SocketError}; use message; use message::{SslRequest, WriteMessage}; @@ -12,15 +12,15 @@ use message::{SslRequest, WriteMessage}; const DEFAULT_PORT: Port = 5432; pub enum MaybeSslStream { - SslStream(ssl::SslStream), - NormalStream(S), + Ssl(ssl::SslStream), + Normal(S), } impl Reader for MaybeSslStream { fn read(&mut self, buf: &mut [u8]) -> IoResult { match *self { - SslStream(ref mut s) => s.read(buf), - NormalStream(ref mut s) => s.read(buf), + MaybeSslStream::Ssl(ref mut s) => s.read(buf), + MaybeSslStream::Normal(ref mut s) => s.read(buf), } } } @@ -28,15 +28,15 @@ impl Reader for MaybeSslStream { impl Writer for MaybeSslStream { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match *self { - SslStream(ref mut s) => s.write(buf), - NormalStream(ref mut s) => s.write(buf), + MaybeSslStream::Ssl(ref mut s) => s.write(buf), + MaybeSslStream::Normal(ref mut s) => s.write(buf), } } fn flush(&mut self) -> IoResult<()> { match *self { - SslStream(ref mut s) => s.flush(), - NormalStream(ref mut s) => s.flush(), + MaybeSslStream::Ssl(ref mut s) => s.flush(), + MaybeSslStream::Normal(ref mut s) => s.flush(), } } } @@ -75,9 +75,9 @@ fn open_socket(params: &ConnectParams) -> Result { let port = params.port.unwrap_or(DEFAULT_PORT); let socket = match params.target { - TargetTcp(ref host) => + ConnectTarget::Tcp(ref host) => tcp::TcpStream::connect(host[], port).map(TcpStream), - TargetUnix(ref path) => { + ConnectTarget::Unix(ref path) => { let mut path = path.clone(); path.push(format!(".s.PGSQL.{}", port)); pipe::UnixStream::connect(&path).map(UnixStream) @@ -91,7 +91,7 @@ pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode) let mut socket = try!(open_socket(params)); let (ssl_required, ctx) = match *ssl { - NoSsl => return Ok(NormalStream(socket)), + NoSsl => return Ok(MaybeSslStream::Normal(socket)), PreferSsl(ref ctx) => (false, ctx), RequireSsl(ref ctx) => (true, ctx) }; @@ -103,12 +103,12 @@ pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode) if ssl_required { return Err(NoSslSupport); } else { - return Ok(NormalStream(socket)); + return Ok(MaybeSslStream::Normal(socket)); } } match ssl::SslStream::new(ctx, socket) { - Ok(stream) => Ok(SslStream(stream)), + Ok(stream) => Ok(MaybeSslStream::Ssl(stream)), Err(err) => Err(SslError(err)) } } diff --git a/src/lib.rs b/src/lib.rs index 16e0656d..b5946bd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,9 +155,9 @@ pub type Result = result::Result; #[deriving(Clone)] pub enum ConnectTarget { /// Connect via TCP to the specified host. - TargetTcp(String), + Tcp(String), /// Connect via a Unix domain socket in the specified directory. - TargetUnix(Path) + Unix(Path) } /// Authentication information @@ -221,9 +221,9 @@ impl IntoConnectParams for Url { let maybe_path = try!(url::decode_component(host[]).map_err(InvalidUrl)); let target = if maybe_path[].starts_with("/") { - TargetUnix(Path::new(maybe_path)) + ConnectTarget::Unix(Path::new(maybe_path)) } else { - TargetTcp(host) + ConnectTarget::Tcp(host) }; let user = user.map(|url::UserInfo { user, pass }| { @@ -737,11 +737,11 @@ impl Connection { /// ``` /// /// ```rust,no_run - /// # use postgres::{Connection, UserInfo, ConnectParams, NoSsl, TargetUnix}; + /// # use postgres::{Connection, UserInfo, ConnectParams, NoSsl, ConnectTarget}; /// # let _ = || { /// # let some_crazy_path = Path::new(""); /// let params = ConnectParams { - /// target: TargetUnix(some_crazy_path), + /// target: ConnectTarget::Unix(some_crazy_path), /// port: None, /// user: Some(UserInfo { /// user: "postgres".into_string(),