Rename Builder to Config

This commit is contained in:
Steven Fackler 2018-12-29 21:00:58 -08:00
parent a3ff1f9a4c
commit 9116147aee
12 changed files with 63 additions and 63 deletions

View File

@ -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,
<T::TlsMode as TlsMode<Socket>>::Future: Send,
{
params.parse::<Builder>()?.connect(tls_mode)
params.parse::<Config>()?.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<Statement, Error> {

View File

@ -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<T>(&mut self, host: T) -> &mut Builder
pub fn host_path<T>(&mut self, host: T) -> &mut Config
where
T: AsRef<Path>,
{
@ -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<T>(&mut self, password: T) -> &mut Builder
pub fn password<T>(&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<Builder, Error> {
s.parse().map(Builder)
fn from_str(s: &str) -> Result<Config, Error> {
s.parse().map(Config)
}
}

View File

@ -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::*;

View File

@ -13,7 +13,7 @@ where
{
let mut runtime = Runtime::new().unwrap();
let builder = s.parse::<tokio_postgres::Builder>().unwrap();
let builder = s.parse::<tokio_postgres::Config>().unwrap();
let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
.map_err(|e| panic!("{}", e))

View File

@ -13,7 +13,7 @@ where
{
let mut runtime = Runtime::new().unwrap();
let builder = s.parse::<tokio_postgres::Builder>().unwrap();
let builder = s.parse::<tokio_postgres::Config>().unwrap();
let handshake = TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
.map_err(|e| panic!("{}", e))

View File

@ -36,21 +36,21 @@ pub(crate) struct Inner {
}
#[derive(Debug, Clone, PartialEq)]
pub struct Builder(pub(crate) Arc<Inner>);
pub struct Config(pub(crate) Arc<Inner>);
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<T>(&mut self, host: T) -> &mut Builder
pub fn host_path<T>(&mut self, host: T) -> &mut Config
where
T: AsRef<Path>,
{
@ -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<T>(&mut self, password: T) -> &mut Builder
pub fn password<T>(&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<Builder, Error> {
fn from_str(s: &str) -> Result<Config, Error> {
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 {

View File

@ -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;

View File

@ -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<T>
@ -12,21 +12,21 @@ where
#[state_machine_future(start, transitions(MakingTlsMode))]
Start {
make_tls_mode: T,
config: Result<Builder, Error>,
config: Result<Config, Error>,
},
#[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<T::TlsMode>,
idx: usize,
make_tls_mode: T,
config: Builder,
config: Config,
},
#[state_machine_future(ready)]
Finished((Client, Connection<T::Stream>)),
@ -118,7 +118,7 @@ impl<T> ConnectFuture<T>
where
T: MakeTlsMode<Socket>,
{
pub fn new(make_tls_mode: T, config: Result<Builder, Error>) -> ConnectFuture<T> {
pub fn new(make_tls_mode: T, config: Result<Config, Error>) -> ConnectFuture<T> {
Connect::start(make_tls_mode, config)
}
}

View File

@ -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<Delay>,
tls_mode: T,
config: Builder,
config: Config,
},
#[state_machine_future(transitions(ConnectingTcp))]
ResolvingDns {
future: CpuFuture<vec::IntoIter<SocketAddr>, io::Error>,
timeout: Option<Delay>,
tls_mode: T,
config: Builder,
config: Config,
},
#[state_machine_future(transitions(Handshaking))]
ConnectingTcp {
@ -59,7 +59,7 @@ where
addrs: vec::IntoIter<SocketAddr>,
timeout: Option<Delay>,
tls_mode: T,
config: Builder,
config: Config,
},
#[state_machine_future(transitions(Finished))]
Handshaking { future: HandshakeFuture<Socket, T> },
@ -214,7 +214,7 @@ impl<T> ConnectOnceFuture<T>
where
T: TlsMode<Socket>,
{
pub fn new(idx: usize, tls_mode: T, config: Builder) -> ConnectOnceFuture<T> {
pub fn new(idx: usize, tls_mode: T, config: Config) -> ConnectOnceFuture<T> {
ConnectOnce::start(idx, tls_mode, config)
}
}

View File

@ -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<S, T>
@ -24,18 +24,18 @@ where
#[state_machine_future(start, transitions(SendingStartup))]
Start {
future: TlsFuture<S, T>,
config: Builder,
config: Config,
},
#[state_machine_future(transitions(ReadingAuth))]
SendingStartup {
future: sink::Send<Framed<T::Stream, PostgresCodec>>,
config: Builder,
config: Config,
channel_binding: ChannelBinding,
},
#[state_machine_future(transitions(ReadingInfo, SendingPassword, SendingSasl))]
ReadingAuth {
stream: Framed<T::Stream, PostgresCodec>,
config: Builder,
config: Config,
channel_binding: ChannelBinding,
},
#[state_machine_future(transitions(ReadingAuthCompletion))]
@ -334,7 +334,7 @@ where
S: AsyncRead + AsyncWrite,
T: TlsMode<S>,
{
pub fn new(stream: S, tls_mode: T, config: Builder) -> HandshakeFuture<S, T> {
pub fn new(stream: S, tls_mode: T, config: Config) -> HandshakeFuture<S, T> {
Handshake::start(TlsFuture::new(stream, tls_mode), config)
}
}

View File

@ -22,7 +22,7 @@ mod types;
fn connect(
s: &str,
) -> impl Future<Item = (Client, Connection<TcpStream>), Error = tokio_postgres::Error> {
let builder = s.parse::<tokio_postgres::Builder>().unwrap();
let builder = s.parse::<tokio_postgres::Config>().unwrap();
TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
.map_err(|e| panic!("{}", e))
.and_then(move |s| builder.handshake(s, NoTls))

View File

@ -1,10 +1,10 @@
#[test]
fn pairs_ok() {
let params = r"user=foo password=' fizz \'buzz\\ ' thing = ''"
.parse::<tokio_postgres::Builder>()
.parse::<tokio_postgres::Config>()
.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::<tokio_postgres::Builder>()
.parse::<tokio_postgres::Config>()
.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);