From 9116147aeece7501f273a8ddb56db5d375d32512 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 29 Dec 2018 21:00:58 -0800 Subject: [PATCH] Rename Builder to Config --- postgres/src/client.rs | 8 ++--- postgres/src/{builder.rs => config.rs} | 32 ++++++++++---------- postgres/src/lib.rs | 4 +-- tokio-postgres-native-tls/src/test.rs | 2 +- tokio-postgres-openssl/src/test.rs | 2 +- tokio-postgres/src/{builder.rs => config.rs} | 32 ++++++++++---------- tokio-postgres/src/lib.rs | 4 +-- tokio-postgres/src/proto/connect.rs | 10 +++--- tokio-postgres/src/proto/connect_once.rs | 12 ++++---- tokio-postgres/src/proto/handshake.rs | 10 +++--- tokio-postgres/tests/test/main.rs | 2 +- tokio-postgres/tests/test/parse.rs | 8 ++--- 12 files changed, 63 insertions(+), 63 deletions(-) rename postgres/src/{builder.rs => config.rs} (66%) rename tokio-postgres/src/{builder.rs => config.rs} (92%) diff --git a/postgres/src/client.rs b/postgres/src/client.rs index f4b9ef3a..93d54da4 100644 --- a/postgres/src/client.rs +++ b/postgres/src/client.rs @@ -6,7 +6,7 @@ use tokio_postgres::Error; use tokio_postgres::{MakeTlsMode, Socket, TlsMode}; #[cfg(feature = "runtime")] -use crate::Builder; +use crate::Config; use crate::{CopyOutReader, Query, Statement, ToStatement, Transaction}; pub struct Client(tokio_postgres::Client); @@ -21,12 +21,12 @@ impl Client { T::Future: Send, >::Future: Send, { - params.parse::()?.connect(tls_mode) + params.parse::()?.connect(tls_mode) } #[cfg(feature = "runtime")] - pub fn builder() -> Builder { - Builder::new() + pub fn builder() -> Config { + Config::new() } pub fn prepare(&mut self, query: &str) -> Result { diff --git a/postgres/src/builder.rs b/postgres/src/config.rs similarity index 66% rename from postgres/src/builder.rs rename to postgres/src/config.rs index 3a1ccfec..5969a1d8 100644 --- a/postgres/src/builder.rs +++ b/postgres/src/config.rs @@ -9,26 +9,26 @@ use tokio_postgres::{Error, MakeTlsMode, Socket, TlsMode}; use crate::{Client, RUNTIME}; #[derive(Debug, Clone, PartialEq)] -pub struct Builder(tokio_postgres::Builder); +pub struct Config(tokio_postgres::Config); -impl Default for Builder { - fn default() -> Builder { - Builder(tokio_postgres::Builder::default()) +impl Default for Config { + fn default() -> Config { + Config(tokio_postgres::Config::default()) } } -impl Builder { - pub fn new() -> Builder { - Builder(tokio_postgres::Builder::new()) +impl Config { + pub fn new() -> Config { + Config(tokio_postgres::Config::new()) } - pub fn host(&mut self, host: &str) -> &mut Builder { + pub fn host(&mut self, host: &str) -> &mut Config { self.0.host(host); self } #[cfg(unix)] - pub fn host_path(&mut self, host: T) -> &mut Builder + pub fn host_path(&mut self, host: T) -> &mut Config where T: AsRef, { @@ -36,22 +36,22 @@ impl Builder { self } - pub fn port(&mut self, port: u16) -> &mut Builder { + pub fn port(&mut self, port: u16) -> &mut Config { self.0.port(port); self } - pub fn param(&mut self, key: &str, value: &str) -> &mut Builder { + pub fn param(&mut self, key: &str, value: &str) -> &mut Config { self.0.param(key, value); self } - pub fn connect_timeout(&mut self, connect_timeout: Duration) -> &mut Builder { + pub fn connect_timeout(&mut self, connect_timeout: Duration) -> &mut Config { self.0.connect_timeout(connect_timeout); self } - pub fn password(&mut self, password: T) -> &mut Builder + pub fn password(&mut self, password: T) -> &mut Config where T: AsRef<[u8]>, { @@ -76,10 +76,10 @@ impl Builder { } } -impl FromStr for Builder { +impl FromStr for Config { type Err = Error; - fn from_str(s: &str) -> Result { - s.parse().map(Builder) + fn from_str(s: &str) -> Result { + s.parse().map(Config) } } diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index ece72ca0..58237696 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -4,7 +4,7 @@ use lazy_static::lazy_static; use tokio::runtime::{self, Runtime}; #[cfg(feature = "runtime")] -mod builder; +mod config; mod client; mod copy_out_reader; mod portal; @@ -19,7 +19,7 @@ mod transaction; mod test; #[cfg(feature = "runtime")] -pub use crate::builder::*; +pub use crate::config::*; pub use crate::client::*; pub use crate::copy_out_reader::*; pub use crate::portal::*; diff --git a/tokio-postgres-native-tls/src/test.rs b/tokio-postgres-native-tls/src/test.rs index 78e7852e..dda907f4 100644 --- a/tokio-postgres-native-tls/src/test.rs +++ b/tokio-postgres-native-tls/src/test.rs @@ -13,7 +13,7 @@ where { let mut runtime = Runtime::new().unwrap(); - let builder = s.parse::().unwrap(); + let builder = s.parse::().unwrap(); let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap()) .map_err(|e| panic!("{}", e)) diff --git a/tokio-postgres-openssl/src/test.rs b/tokio-postgres-openssl/src/test.rs index 9ca6ffca..9a123849 100644 --- a/tokio-postgres-openssl/src/test.rs +++ b/tokio-postgres-openssl/src/test.rs @@ -13,7 +13,7 @@ where { let mut runtime = Runtime::new().unwrap(); - let builder = s.parse::().unwrap(); + let builder = s.parse::().unwrap(); let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap()) .map_err(|e| panic!("{}", e)) diff --git a/tokio-postgres/src/builder.rs b/tokio-postgres/src/config.rs similarity index 92% rename from tokio-postgres/src/builder.rs rename to tokio-postgres/src/config.rs index 998e4843..f5510443 100644 --- a/tokio-postgres/src/builder.rs +++ b/tokio-postgres/src/config.rs @@ -36,21 +36,21 @@ pub(crate) struct Inner { } #[derive(Debug, Clone, PartialEq)] -pub struct Builder(pub(crate) Arc); +pub struct Config(pub(crate) Arc); -impl Default for Builder { - fn default() -> Builder { - Builder::new() +impl Default for Config { + fn default() -> Config { + Config::new() } } -impl Builder { - pub fn new() -> Builder { +impl Config { + pub fn new() -> Config { let mut params = HashMap::new(); params.insert("client_encoding".to_string(), "UTF8".to_string()); params.insert("timezone".to_string(), "GMT".to_string()); - Builder(Arc::new(Inner { + Config(Arc::new(Inner { params, password: None, #[cfg(feature = "runtime")] @@ -63,7 +63,7 @@ impl Builder { } #[cfg(feature = "runtime")] - pub fn host(&mut self, host: &str) -> &mut Builder { + pub fn host(&mut self, host: &str) -> &mut Config { #[cfg(unix)] { if host.starts_with('/') { @@ -78,7 +78,7 @@ impl Builder { } #[cfg(all(feature = "runtime", unix))] - pub fn host_path(&mut self, host: T) -> &mut Builder + pub fn host_path(&mut self, host: T) -> &mut Config where T: AsRef, { @@ -89,18 +89,18 @@ impl Builder { } #[cfg(feature = "runtime")] - pub fn port(&mut self, port: u16) -> &mut Builder { + pub fn port(&mut self, port: u16) -> &mut Config { Arc::make_mut(&mut self.0).port.push(port); self } #[cfg(feature = "runtime")] - pub fn connect_timeout(&mut self, connect_timeout: Duration) -> &mut Builder { + pub fn connect_timeout(&mut self, connect_timeout: Duration) -> &mut Config { Arc::make_mut(&mut self.0).connect_timeout = Some(connect_timeout); self } - pub fn password(&mut self, password: T) -> &mut Builder + pub fn password(&mut self, password: T) -> &mut Config where T: AsRef<[u8]>, { @@ -108,7 +108,7 @@ impl Builder { self } - pub fn param(&mut self, key: &str, value: &str) -> &mut Builder { + pub fn param(&mut self, key: &str, value: &str) -> &mut Config { Arc::make_mut(&mut self.0) .params .insert(key.to_string(), value.to_string()); @@ -132,12 +132,12 @@ impl Builder { } } -impl FromStr for Builder { +impl FromStr for Config { type Err = Error; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { let mut parser = Parser::new(s); - let mut builder = Builder::new(); + let mut builder = Config::new(); while let Some((key, value)) = parser.parameter()? { match key { diff --git a/tokio-postgres/src/lib.rs b/tokio-postgres/src/lib.rs index 2b160a3e..0e491480 100644 --- a/tokio-postgres/src/lib.rs +++ b/tokio-postgres/src/lib.rs @@ -6,7 +6,7 @@ use std::error::Error as StdError; use std::sync::atomic::{AtomicUsize, Ordering}; use tokio_io::{AsyncRead, AsyncWrite}; -pub use crate::builder::*; +pub use crate::config::*; pub use crate::error::*; use crate::proto::CancelFuture; pub use crate::row::*; @@ -16,7 +16,7 @@ pub use crate::stmt::Column; pub use crate::tls::*; use crate::types::{ToSql, Type}; -mod builder; +mod config; pub mod error; mod proto; mod row; diff --git a/tokio-postgres/src/proto/connect.rs b/tokio-postgres/src/proto/connect.rs index d272db16..d37f32e5 100644 --- a/tokio-postgres/src/proto/connect.rs +++ b/tokio-postgres/src/proto/connect.rs @@ -2,7 +2,7 @@ use futures::{try_ready, Async, Future, Poll}; use state_machine_future::{transition, RentToOwn, StateMachineFuture}; use crate::proto::{Client, ConnectOnceFuture, Connection}; -use crate::{Builder, Error, Host, MakeTlsMode, Socket}; +use crate::{Config, Error, Host, MakeTlsMode, Socket}; #[derive(StateMachineFuture)] pub enum Connect @@ -12,21 +12,21 @@ where #[state_machine_future(start, transitions(MakingTlsMode))] Start { make_tls_mode: T, - config: Result, + config: Result, }, #[state_machine_future(transitions(Connecting))] MakingTlsMode { future: T::Future, idx: usize, make_tls_mode: T, - config: Builder, + config: Config, }, #[state_machine_future(transitions(MakingTlsMode, Finished))] Connecting { future: ConnectOnceFuture, idx: usize, make_tls_mode: T, - config: Builder, + config: Config, }, #[state_machine_future(ready)] Finished((Client, Connection)), @@ -118,7 +118,7 @@ impl ConnectFuture where T: MakeTlsMode, { - pub fn new(make_tls_mode: T, config: Result) -> ConnectFuture { + pub fn new(make_tls_mode: T, config: Result) -> ConnectFuture { Connect::start(make_tls_mode, config) } } diff --git a/tokio-postgres/src/proto/connect_once.rs b/tokio-postgres/src/proto/connect_once.rs index 70471bc6..2c21f8d8 100644 --- a/tokio-postgres/src/proto/connect_once.rs +++ b/tokio-postgres/src/proto/connect_once.rs @@ -16,7 +16,7 @@ use tokio_timer::Delay; use tokio_uds::UnixStream; use crate::proto::{Client, Connection, HandshakeFuture}; -use crate::{Builder, Error, Host, Socket, TlsMode}; +use crate::{Config, Error, Host, Socket, TlsMode}; lazy_static! { static ref DNS_POOL: CpuPool = futures_cpupool::Builder::new() @@ -36,7 +36,7 @@ where Start { idx: usize, tls_mode: T, - config: Builder, + config: Config, }, #[cfg(unix)] #[state_machine_future(transitions(Handshaking))] @@ -44,14 +44,14 @@ where future: tokio_uds::ConnectFuture, timeout: Option, tls_mode: T, - config: Builder, + config: Config, }, #[state_machine_future(transitions(ConnectingTcp))] ResolvingDns { future: CpuFuture, io::Error>, timeout: Option, tls_mode: T, - config: Builder, + config: Config, }, #[state_machine_future(transitions(Handshaking))] ConnectingTcp { @@ -59,7 +59,7 @@ where addrs: vec::IntoIter, timeout: Option, tls_mode: T, - config: Builder, + config: Config, }, #[state_machine_future(transitions(Finished))] Handshaking { future: HandshakeFuture }, @@ -214,7 +214,7 @@ impl ConnectOnceFuture where T: TlsMode, { - pub fn new(idx: usize, tls_mode: T, config: Builder) -> ConnectOnceFuture { + pub fn new(idx: usize, tls_mode: T, config: Config) -> ConnectOnceFuture { ConnectOnce::start(idx, tls_mode, config) } } diff --git a/tokio-postgres/src/proto/handshake.rs b/tokio-postgres/src/proto/handshake.rs index 1da91ff0..36790528 100644 --- a/tokio-postgres/src/proto/handshake.rs +++ b/tokio-postgres/src/proto/handshake.rs @@ -13,7 +13,7 @@ use tokio_codec::Framed; use tokio_io::{AsyncRead, AsyncWrite}; use crate::proto::{Client, Connection, PostgresCodec, TlsFuture}; -use crate::{Builder, CancelData, ChannelBinding, Error, TlsMode}; +use crate::{CancelData, ChannelBinding, Config, Error, TlsMode}; #[derive(StateMachineFuture)] pub enum Handshake @@ -24,18 +24,18 @@ where #[state_machine_future(start, transitions(SendingStartup))] Start { future: TlsFuture, - config: Builder, + config: Config, }, #[state_machine_future(transitions(ReadingAuth))] SendingStartup { future: sink::Send>, - config: Builder, + config: Config, channel_binding: ChannelBinding, }, #[state_machine_future(transitions(ReadingInfo, SendingPassword, SendingSasl))] ReadingAuth { stream: Framed, - config: Builder, + config: Config, channel_binding: ChannelBinding, }, #[state_machine_future(transitions(ReadingAuthCompletion))] @@ -334,7 +334,7 @@ where S: AsyncRead + AsyncWrite, T: TlsMode, { - pub fn new(stream: S, tls_mode: T, config: Builder) -> HandshakeFuture { + pub fn new(stream: S, tls_mode: T, config: Config) -> HandshakeFuture { Handshake::start(TlsFuture::new(stream, tls_mode), config) } } diff --git a/tokio-postgres/tests/test/main.rs b/tokio-postgres/tests/test/main.rs index 1f72a7ea..59f01238 100644 --- a/tokio-postgres/tests/test/main.rs +++ b/tokio-postgres/tests/test/main.rs @@ -22,7 +22,7 @@ mod types; fn connect( s: &str, ) -> impl Future), Error = tokio_postgres::Error> { - let builder = s.parse::().unwrap(); + let builder = s.parse::().unwrap(); TcpStream::connect(&"127.0.0.1:5433".parse().unwrap()) .map_err(|e| panic!("{}", e)) .and_then(move |s| builder.handshake(s, NoTls)) diff --git a/tokio-postgres/tests/test/parse.rs b/tokio-postgres/tests/test/parse.rs index c5d2e0fa..ac320d20 100644 --- a/tokio-postgres/tests/test/parse.rs +++ b/tokio-postgres/tests/test/parse.rs @@ -1,10 +1,10 @@ #[test] fn pairs_ok() { let params = r"user=foo password=' fizz \'buzz\\ ' thing = ''" - .parse::() + .parse::() .unwrap(); - let mut expected = tokio_postgres::Builder::new(); + let mut expected = tokio_postgres::Config::new(); expected .param("user", "foo") .password(r" fizz 'buzz\ ") @@ -16,10 +16,10 @@ fn pairs_ok() { #[test] fn pairs_ws() { let params = " user\t=\r\n\x0bfoo \t password = hunter2 " - .parse::() + .parse::() .unwrap();; - let mut expected = tokio_postgres::Builder::new(); + let mut expected = tokio_postgres::Config::new(); expected.param("user", "foo").password("hunter2"); assert_eq!(params, expected);