diff --git a/.travis.yml b/.travis.yml index 18f70a2d..4a73695a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,5 @@ before_script: - "./.travis/setup.sh" script: - cargo test -- cargo test --features "uuid rustc-serialize time unix_socket serde_json chrono with-openssl bit-vec eui48" +- cargo test --features "with-uuid with-rustc-serialize with-time with-unix_socket with-serde_json with-chrono with-openssl with-bit-vec with-eui48" - (test $TRAVIS_RUST_VERSION != "nightly" || cargo test --features nightly) diff --git a/Cargo.toml b/Cargo.toml index 168fd090..20f32e8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,25 +22,34 @@ path = "tests/test.rs" [features] nightly = [] +with-bit-vec = ["bit-vec"] +with-chrono = ["chrono"] +with-eui48 = ["eui48"] with-openssl = ["openssl", "openssl-verify"] +with-rustc-serialize = ["rustc-serialize"] +with-security-framework = ["security-framework"] +with-serde_json = ["serde_json"] +with-time = ["time"] +with-unix_socket = ["unix_socket"] +with-uuid = ["uuid"] [dependencies] bufstream = "0.1" byteorder = "0.5" +hex = "0.2" log = "0.3" phf = "=0.7.15" -hex = "0.2" -rustc-serialize = { version = "0.3", optional = true } +bit-vec = { version = "0.4", optional = true } chrono = { version = "0.2.14", optional = true } +eui48 = { version = "0.1", optional = true } openssl = { version = ">= 0.6.4, < 0.8", optional = true } openssl-verify = { version = "0.1", optional = true } +rustc-serialize = { version = "0.3", optional = true } +security-framework = { version = "0.1.2", optional = true } serde_json = { version = ">= 0.6, < 0.9", optional = true } time = { version = "0.1.14", optional = true } unix_socket = { version = "0.5", optional = true } uuid = { version = ">= 0.1, < 0.4", optional = true } -security-framework = { version = "0.1.2", optional = true } -bit-vec = { version = "0.4", optional = true } -eui48 = { version = "0.1", optional = true } [dev-dependencies] url = "1.0" diff --git a/README.md b/README.md index f4cdcea9..a09b3966 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ let conn = try!(Connection::connect("postgres://user:pass@host:port/database?arg defaults to the value of `user` if not specified. The driver supports `trust`, `password`, and `md5` authentication. -Unix domain sockets can be used as well by activating the `unix_socket` or +Unix domain sockets can be used as well by activating the `with-unix_socket` or `nightly` features. The `host` portion of the URI should be set to the absolute path to the directory containing the socket file. Since `/` is a reserved character in URLs, the path should be URL encoded. If Postgres stored its socket @@ -288,39 +288,39 @@ crate. ### Unix socket connections Support for connections through Unix domain sockets is provided optionally by -either the `unix_socket` or `nightly` features. It is only available on "unixy" -platforms such as OSX, BSD and Linux. +either the `with-unix_socket` or `nightly` features. It is only available on +"unixy" platforms such as OSX, BSD and Linux. ### UUID type [UUID](http://www.postgresql.org/docs/9.4/static/datatype-uuid.html) support is -provided optionally by the `uuid` feature, which adds `ToSql` and `FromSql` +provided optionally by the `with-uuid` feature, which adds `ToSql` and `FromSql` implementations for `uuid`'s `Uuid` type. ### JSON/JSONB types [JSON and JSONB](http://www.postgresql.org/docs/9.4/static/datatype-json.html) -support is provided optionally by the `rustc-serialize` feature, which adds +support is provided optionally by the `with-rustc-serialize` feature, which adds `ToSql` and `FromSql` implementations for `rustc-serialize`'s `Json` type, and -the `serde_json` feature, which adds implementations for `serde_json`'s `Value` -type. +the `with-serde_json` feature, which adds implementations for `serde_json`'s +`Value` type. ### TIMESTAMP/TIMESTAMPTZ/DATE/TIME types [Date and Time](http://www.postgresql.org/docs/9.1/static/datatype-datetime.html) -support is provided optionally by the `time` feature, which adds `ToSql` and -`FromSql` implementations for `time`'s `Timespec` type, or the `chrono` +support is provided optionally by the `with-time` feature, which adds `ToSql` +and `FromSql` implementations for `time`'s `Timespec` type, or the `with-chrono` feature, which adds `ToSql` and `FromSql` implementations for `chrono`'s `DateTime`, `NaiveDateTime`, `NaiveDate` and `NaiveTime` types. ### BIT/VARBIT types [BIT and VARBIT](http://www.postgresql.org/docs/9.4/static/datatype-bit.html) -support is provided optionally by the `bit-vec` feature, which adds `ToSql` and -`FromSql` implementations for `bit-vec`'s `BitVec` type. +support is provided optionally by the `with-bit-vec` feature, which adds `ToSql` +and `FromSql` implementations for `bit-vec`'s `BitVec` type. ### MACADDR type [MACADDR](http://www.postgresql.org/docs/9.4/static/datatype-net-types.html#DATATYPE-MACADDR) -support is provided optionally by the `eui48` feature, which adds `ToSql` and -`FromSql` implementations for `eui48`'s `MacAddress` type. +support is provided optionally by the `with-eui48` feature, which adds `ToSql` +and `FromSql` implementations for `eui48`'s `MacAddress` type. diff --git a/src/feature_check.rs b/src/feature_check.rs new file mode 100644 index 00000000..dc39b19c --- /dev/null +++ b/src/feature_check.rs @@ -0,0 +1,29 @@ +#[cfg(all(feature = "bit-vec", not(feature = "with-bit-vec")))] +const _CHECK: BitVecFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "chrono", not(feature = "with-chrono")))] +const _CHECK: ChronoFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "eui48", not(feature = "with-eui48")))] +const _CHECK: Eui48FeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "openssl", not(feature = "with-openssl")))] +const _CHECK: OpensslFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "rustc-serialize", not(feature = "with-rustc-serialize")))] +const _CHECK: RustcSerializeFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "security-framework", not(feature = "with-security-framework")))] +const _CHECK: SecurityFrameworkFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "serde_json", not(feature = "with-serde_json")))] +const _CHECK: SerdeJsonFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "time", not(feature = "with-time")))] +const _CHECK: TimeFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "unix_socket", not(feature = "with-unix_socket")))] +const _CHECK: UnixSocketFeatureRenamedSeeDocs = (); + +#[cfg(all(feature = "uuid", not(feature = "with-uuid")))] +const _CHECK: UuidFeatureRenamedSeeDocs = (); diff --git a/src/io/mod.rs b/src/io/mod.rs index 892f59f2..ef0b354c 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -7,12 +7,9 @@ use std::fmt; #[cfg(feature = "with-openssl")] pub mod openssl; -#[cfg(feature = "security-framework")] +#[cfg(feature = "with-security-framework")] pub mod security_framework; -#[cfg(all(feature = "openssl", not(feature = "with-openssl")))] -const _CHECK: OpensslFeatureRenamedSeeDocs = ""; - /// A trait implemented by TLS adaptors. pub trait TlsStream: fmt::Debug + Read + Write + Send { /// Returns a reference to the underlying `Stream`. diff --git a/src/io/security_framework.rs b/src/io/security_framework.rs index e00f11e4..d51335fb 100644 --- a/src/io/security_framework.rs +++ b/src/io/security_framework.rs @@ -17,7 +17,7 @@ impl TlsStream for SslStream { /// A `TlsHandshake` implementation that uses the Security Framework. /// -/// Requires the `security-framework` feature. +/// Requires the `with-security-framework` feature. #[derive(Debug)] pub struct SecurityFramework(ClientBuilder); diff --git a/src/lib.rs b/src/lib.rs index e395158a..63f58112 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ extern crate hex; #[macro_use] extern crate log; extern crate phf; -#[cfg(feature = "unix_socket")] +#[cfg(feature = "with-unix_socket")] extern crate unix_socket; use bufstream::BufStream; @@ -64,7 +64,7 @@ use std::mem; use std::result; use std::sync::Arc; use std::time::Duration; -#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] +#[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] use std::path::PathBuf; use error::{Error, ConnectError, SqlState, DbError}; @@ -81,6 +81,7 @@ use transaction::{Transaction, IsolationLevel}; #[macro_use] mod macros; +mod feature_check; mod md5; mod message; mod priv_io; @@ -165,14 +166,14 @@ impl<'a> IntoConnectParams for &'a str { impl IntoConnectParams for Url { fn into_connect_params(self) -> result::Result> { - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] fn make_unix(maybe_path: String) -> result::Result> { Ok(ConnectTarget::Unix(PathBuf::from(maybe_path))) } - #[cfg(not(any(feature = "unix_socket", all(unix, feature = "nightly"))))] + #[cfg(not(any(feature = "with-unix_socket", all(unix, feature = "nightly"))))] fn make_unix(_: String) -> result::Result> { - Err("unix socket support requires the `unix_socket` or `nightly` features".into()) + Err("unix socket support requires the `with-unix_socket` or `nightly` features".into()) } let Url { host, port, user, path: url::Path { mut path, query: options, .. }, .. } = self; @@ -983,13 +984,13 @@ impl Connection { /// (5432) is used if none is specified. The database name defaults to the /// username if not specified. /// - /// Connection via Unix sockets is supported with either the `unix_socket` - /// or `nightly` features. To connect to the server via Unix sockets, `host` - /// should be set to the absolute path of the directory containing the - /// socket file. Since `/` is a reserved character in URLs, the path should - /// be URL encoded. If the path contains non-UTF 8 characters, a - /// `ConnectParams` struct should be created manually and passed in. Note - /// that Postgres does not support SSL over Unix sockets. + /// Connection via Unix sockets is supported with either the + /// `with-unix_socket` or `nightly` features. To connect to the server via + /// Unix sockets, `host` should be set to the absolute path of the directory + /// containing the socket file. Since `/` is a reserved character in URLs, + /// the path should be URL encoded. If the path contains non-UTF 8 + /// characters, a `ConnectParams` struct should be created manually and + /// passed in. Note that Postgres does not support SSL over Unix sockets. /// /// # Examples /// @@ -1011,7 +1012,7 @@ impl Connection { /// use postgres::{Connection, UserInfo, ConnectParams, TlsMode, ConnectTarget}; /// # use std::path::PathBuf; /// - /// # #[cfg(feature = "unix_socket")] + /// # #[cfg(feature = "with-unix_socket")] /// # fn f() { /// # let some_crazy_path = PathBuf::new(); /// let params = ConnectParams { diff --git a/src/priv_io.rs b/src/priv_io.rs index 79a0e599..4f67fd53 100644 --- a/src/priv_io.rs +++ b/src/priv_io.rs @@ -6,9 +6,9 @@ use std::fmt; use std::net::TcpStream; use std::time::Duration; use bufstream::BufStream; -#[cfg(feature = "unix_socket")] +#[cfg(feature = "with-unix_socket")] use unix_socket::UnixStream; -#[cfg(all(not(feature = "unix_socket"), all(unix, feature = "nightly")))] +#[cfg(all(not(feature = "with-unix_socket"), all(unix, feature = "nightly")))] use std::os::unix::net::UnixStream; #[cfg(unix)] use std::os::unix::io::{AsRawFd, RawFd}; @@ -33,7 +33,7 @@ impl StreamOptions for BufStream> { fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { match self.get_ref().get_ref().0 { InternalStream::Tcp(ref s) => s.set_read_timeout(timeout), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.set_read_timeout(timeout), } } @@ -41,7 +41,7 @@ impl StreamOptions for BufStream> { fn set_nonblocking(&self, nonblock: bool) -> io::Result<()> { match self.get_ref().get_ref().0 { InternalStream::Tcp(ref s) => s.set_nonblocking(nonblock), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.set_nonblocking(nonblock), } } @@ -57,7 +57,7 @@ impl fmt::Debug for Stream { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self.0 { InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt), } } @@ -94,7 +94,7 @@ impl AsRawFd for Stream { fn as_raw_fd(&self) -> RawFd { match self.0 { InternalStream::Tcp(ref s) => s.as_raw_fd(), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.as_raw_fd(), } } @@ -112,7 +112,7 @@ impl AsRawSocket for Stream { enum InternalStream { Tcp(TcpStream), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] Unix(UnixStream), } @@ -120,7 +120,7 @@ impl Read for InternalStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { match *self { InternalStream::Tcp(ref mut s) => s.read(buf), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.read(buf), } } @@ -130,7 +130,7 @@ impl Write for InternalStream { fn write(&mut self, buf: &[u8]) -> io::Result { match *self { InternalStream::Tcp(ref mut s) => s.write(buf), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.write(buf), } } @@ -138,7 +138,7 @@ impl Write for InternalStream { fn flush(&mut self) -> io::Result<()> { match *self { InternalStream::Tcp(ref mut s) => s.flush(), - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.flush(), } } @@ -150,7 +150,7 @@ fn open_socket(params: &ConnectParams) -> Result { ConnectTarget::Tcp(ref host) => { Ok(try!(TcpStream::connect(&(&**host, port)).map(InternalStream::Tcp))) } - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] ConnectTarget::Unix(ref path) => { let path = path.join(&format!(".s.PGSQL.{}", port)); Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix))) @@ -184,7 +184,7 @@ pub fn initialize_stream(params: &ConnectParams, // Postgres doesn't support SSL over unix sockets let host = match params.target { ConnectTarget::Tcp(ref host) => host, - #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] + #[cfg(any(feature = "with-unix_socket", all(unix, feature = "nightly")))] ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())), }; diff --git a/src/types/mod.rs b/src/types/mod.rs index 9fa8d952..3ac7df79 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -54,19 +54,19 @@ pub fn __to_sql_checked(v: &T, ty: &Type, out: &mut Write, ctx: &SessionInfo) v.to_sql(ty, out, ctx) } -#[cfg(feature = "bit-vec")] +#[cfg(feature = "with-bit-vec")] mod bit_vec; -#[cfg(feature = "uuid")] +#[cfg(feature = "with-uuid")] mod uuid; -#[cfg(feature = "time")] +#[cfg(feature = "with-time")] mod time; -#[cfg(feature = "rustc-serialize")] +#[cfg(feature = "with-rustc-serialize")] mod rustc_serialize; -#[cfg(feature = "serde_json")] +#[cfg(feature = "with-serde_json")] mod serde_json; -#[cfg(feature = "chrono")] +#[cfg(feature = "with-chrono")] mod chrono; -#[cfg(feature = "eui48")] +#[cfg(feature = "with-eui48")] mod eui48; mod special; @@ -273,8 +273,8 @@ impl WrongTypeNew for WrongType { /// In addition, some implementations are provided for types in third party /// crates. These are disabled by default; to opt into one of these /// implementations, activate the Cargo feature corresponding to the crate's -/// name. For example, the `serde_json` feature enables the implementation for -/// the `serde_json::Value` type. +/// name prefixed by `with-`. For example, the `with-serde_json` feature enables +/// the implementation for the `serde_json::Value` type. /// /// | Rust type | Postgres type(s) | /// |---------------------------------|-------------------------------------| @@ -525,8 +525,8 @@ pub enum IsNull { /// In addition, some implementations are provided for types in third party /// crates. These are disabled by default; to opt into one of these /// implementations, activate the Cargo feature corresponding to the crate's -/// name. For example, the `serde_json` feature enables the implementation for -/// the `serde_json::Value` type. +/// name prefixed by `with-`. For example, the `with-serde_json` feature enables +/// the implementation for the `serde_json::Value` type. /// /// | Rust type | Postgres type(s) | /// |---------------------------------|-------------------------------------| diff --git a/tests/test.rs b/tests/test.rs index debd89d1..884eae6a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -3,7 +3,7 @@ extern crate postgres; extern crate url; #[cfg(feature = "with-openssl")] extern crate openssl; -#[cfg(feature = "security-framework")] +#[cfg(feature = "with-security-framework")] extern crate security_framework; use std::thread; @@ -685,7 +685,7 @@ fn test_prefer_ssl_conn() { } #[test] -#[cfg(feature = "security-framework")] +#[cfg(feature = "with-security-framework")] fn security_framework_ssl() { use postgres::io::security_framework::SecurityFramework; use security_framework::certificate::SecCertificate; diff --git a/tests/types/mod.rs b/tests/types/mod.rs index 6030d7da..62db4255 100644 --- a/tests/types/mod.rs +++ b/tests/types/mod.rs @@ -8,19 +8,19 @@ use postgres::{Connection, TlsMode, Result}; use postgres::error::Error; use postgres::types::{ToSql, FromSql, WrongType, Type, IsNull, Kind, SessionInfo}; -#[cfg(feature = "bit-vec")] +#[cfg(feature = "with-bit-vec")] mod bit_vec; -#[cfg(feature = "eui48")] +#[cfg(feature = "with-eui48")] mod eui48; -#[cfg(feature = "uuid")] +#[cfg(feature = "with-uuid")] mod uuid; -#[cfg(feature = "time")] +#[cfg(feature = "with-time")] mod time; -#[cfg(feature = "rustc-serialize")] +#[cfg(feature = "with-rustc-serialize")] mod rustc_serialize; -#[cfg(feature = "serde_json")] +#[cfg(feature = "with-serde_json")] mod serde_json; -#[cfg(feature = "chrono")] +#[cfg(feature = "with-chrono")] mod chrono; fn test_type(sql_type: &str, checks: &[(T, S)]) {