@@ -53,12 +53,10 @@ use bufstream::BufStream;
5353use md5:: Md5 ;
5454use std:: cell:: { Cell , RefCell } ;
5555use std:: collections:: { VecDeque , HashMap } ;
56- use std:: error:: Error as StdError ;
5756use std:: fmt;
5857use std:: io as std_io;
5958use std:: io:: prelude:: * ;
6059use std:: mem;
61- use std:: path:: PathBuf ;
6260use std:: result;
6361use std:: sync:: Arc ;
6462use std:: time:: Duration ;
@@ -68,10 +66,10 @@ use io::{TlsStream, TlsHandshake};
6866use message:: { Frontend , Backend , RowDescriptionEntry } ;
6967use message:: { WriteMessage , ReadMessage } ;
7068use notification:: { Notifications , Notification } ;
69+ use params:: { ConnectParams , IntoConnectParams , UserInfo } ;
7170use rows:: { Rows , LazyRows } ;
7271use stmt:: { Statement , Column } ;
7372use types:: { IsNull , Kind , Type , SessionInfo , Oid , Other , WrongType , ToSql , FromSql , Field } ;
74- use url:: Url ;
7573use transaction:: { Transaction , IsolationLevel } ;
7674
7775#[ macro_use]
@@ -85,6 +83,7 @@ mod url;
8583pub mod error;
8684pub mod io;
8785pub mod notification;
86+ pub mod params;
8887pub mod rows;
8988pub mod stmt;
9089pub mod transaction;
@@ -97,104 +96,6 @@ const TYPEINFO_COMPOSITE_QUERY: &'static str = "__typeinfo_composite";
9796/// A type alias of the result returned by many methods.
9897pub type Result < T > = result:: Result < T , Error > ;
9998
100- /// Specifies the target server to connect to.
101- #[ derive( Clone , Debug ) ]
102- pub enum ConnectTarget {
103- /// Connect via TCP to the specified host.
104- Tcp ( String ) ,
105- /// Connect via a Unix domain socket in the specified directory.
106- ///
107- /// Unix sockets are only supported on Unixy platforms (i.e. not Windows).
108- Unix ( PathBuf ) ,
109- }
110-
111- /// Authentication information.
112- #[ derive( Clone , Debug ) ]
113- pub struct UserInfo {
114- /// The username.
115- pub user : String ,
116- /// An optional password.
117- pub password : Option < String > ,
118- }
119-
120- /// Information necessary to open a new connection to a Postgres server.
121- #[ derive( Clone , Debug ) ]
122- pub struct ConnectParams {
123- /// The target server.
124- pub target : ConnectTarget ,
125- /// The target port.
126- ///
127- /// Defaults to 5432 if not specified.
128- pub port : Option < u16 > ,
129- /// The user to login as.
130- ///
131- /// `Connection::connect` requires a user but `cancel_query` does not.
132- pub user : Option < UserInfo > ,
133- /// The database to connect to.
134- ///
135- /// Defaults the value of `user`.
136- pub database : Option < String > ,
137- /// Runtime parameters to be passed to the Postgres backend.
138- pub options : Vec < ( String , String ) > ,
139- }
140-
141- /// A trait implemented by types that can be converted into a `ConnectParams`.
142- pub trait IntoConnectParams {
143- /// Converts the value of `self` into a `ConnectParams`.
144- fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + Sync + Send > > ;
145- }
146-
147- impl IntoConnectParams for ConnectParams {
148- fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + Sync + Send > > {
149- Ok ( self )
150- }
151- }
152-
153- impl < ' a > IntoConnectParams for & ' a str {
154- fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + Sync + Send > > {
155- match Url :: parse ( self ) {
156- Ok ( url) => url. into_connect_params ( ) ,
157- Err ( err) => Err ( err. into ( ) ) ,
158- }
159- }
160- }
161-
162- impl IntoConnectParams for Url {
163- fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + Sync + Send > > {
164- let Url { host, port, user, path : url:: Path { mut path, query : options, .. } , .. } = self ;
165-
166- let maybe_path = try!( url:: decode_component ( & host) ) ;
167- let target = if maybe_path. starts_with ( '/' ) {
168- ConnectTarget :: Unix ( PathBuf :: from ( maybe_path) )
169- } else {
170- ConnectTarget :: Tcp ( host)
171- } ;
172-
173- let user = user. map ( |url:: UserInfo { user, pass } | {
174- UserInfo {
175- user : user,
176- password : pass,
177- }
178- } ) ;
179-
180- let database = if path. is_empty ( ) {
181- None
182- } else {
183- // path contains the leading /
184- path. remove ( 0 ) ;
185- Some ( path)
186- } ;
187-
188- Ok ( ConnectParams {
189- target : target,
190- port : port,
191- user : user,
192- database : database,
193- options : options,
194- } )
195- }
196- }
197-
19899/// Trait for types that can handle Postgres notice messages
199100///
200101/// It is implemented for all `Send + FnMut(DbError)` closures.
@@ -993,7 +894,8 @@ impl Connection {
993894 /// ```
994895 ///
995896 /// ```rust,no_run
996- /// use postgres::{Connection, UserInfo, ConnectParams, TlsMode, ConnectTarget};
897+ /// use postgres::{Connection, TlsMode};
898+ /// use postgres::params::{UserInfo, ConnectParams, ConnectTarget};
997899 /// # use std::path::PathBuf;
998900 ///
999901 /// # #[cfg(unix)]
0 commit comments