Skip to content

Commit

Permalink
Merge pull request #299 from blackbeam/fix-features
Browse files Browse the repository at this point in the history
Fix imports for non-default features
  • Loading branch information
blackbeam authored Mar 20, 2024
2 parents 5a807d9 + d8fe660 commit 976a527
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ rustls-tls = [
"rustls-pemfile",
]

binlog = ["mysql_common/binlog"]

# mysql_common features
derive = ["mysql_common/derive"]
chrono = ["mysql_common/chrono"]
time = ["mysql_common/time"]
bigdecimal = ["mysql_common/bigdecimal"]
rust_decimal = ["mysql_common/rust_decimal"]
frunk = ["mysql_common/frunk"]
binlog = ["mysql_common/binlog"]

# other features
tracing = ["dep:tracing"]
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,18 @@ as well as `native-tls`-based TLS support.
mysql_async = { version = "*", default-features = false, features = ["minimal"]}
```

**Note:* it is possible to use another `flate2` backend by directly choosing it:
* `minimal-rust` - same as `minimal` but rust-based flate2 backend is chosen. Enables:

```toml
[dependencies]
mysql_async = { version = "*", default-features = false }
flate2 = { version = "*", default-features = false, features = ["rust_backend"] }
```
- `flate2/rust_backend`

* `default` – enables the following set of crate's and dependencies' features:
* `default` – enables the following set of features:

- `minimal`
- `native-tls-tls`
- `flate2/zlib"
- `mysql_common/bigdecimal03`
- `mysql_common/rust_decimal`
- `mysql_common/time03`
- `mysql_common/uuid`
- `mysql_common/frunk`
- `bigdecimal`
- `rust_decimal`
- `time`
- `frunk`
- `binlog`

* `default-rustls` – same as default but with `rustls-tls` instead of `native-tls-tls`.
Expand Down Expand Up @@ -95,12 +90,19 @@ as well as `native-tls`-based TLS support.
mysql_async = { version = "*", features = ["tracing"] }
```

* `derive` – enables `mysql_commom/derive` feature

* `binlog` - enables binlog-related functionality. Enables:

- `mysql_common/binlog"

#### Proxied features

* `derive` – enables `mysql_common/derive` feature
* `chrono` = enables `mysql_common/chrono` feature
* `time` = enables `mysql_common/time` feature
* `bigdecimal` = enables `mysql_common/bigdecimal` feature
* `rust_decimal` = enables `mysql_common/rust_decimal` feature
* `frunk` = enables `mysql_common/frunk` feature

[myslqcommonfeatures]: https://github.com/blackbeam/rust_mysql_common#crate-features

## TLS/SSL Support
Expand Down
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
SSL=false COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test
SSL=true COMPRESS=false cargo test --no-default-features --features default-rustls
SSL=true COMPRESS=false cargo check --no-default-features --features minimal
SSL=true COMPRESS=false cargo check --no-default-features --features minimal-rust
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root:[email protected]:3306/mysql
Expand Down
1 change: 0 additions & 1 deletion src/conn/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
borrow::Borrow,
cmp::Reverse,
collections::VecDeque,
convert::TryFrom,
hash::{Hash, Hasher},
str::FromStr,
sync::{atomic, Arc, Mutex},
Expand Down
4 changes: 2 additions & 2 deletions src/error/tls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#![cfg(any(feature = "native-tls-tls", feature = "rustls-tls"))]

pub mod native_tls_error;
pub mod rustls_error;

#[cfg(feature = "native-tls")]
#[cfg(feature = "native-tls-tls")]
pub use native_tls_error::TlsError;

#[cfg(feature = "rustls")]
Expand Down
2 changes: 1 addition & 1 deletion src/error/tls/native_tls_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "native-tls")]
#![cfg(feature = "native-tls-tls")]

use std::fmt::Display;

Expand Down
4 changes: 2 additions & 2 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Endpoint {
matches!(self, Endpoint::Secure(_))
}

#[cfg(all(not(feature = "native-tls"), not(feature = "rustls")))]
#[cfg(all(not(feature = "native-tls-tls"), not(feature = "rustls")))]
pub async fn make_secure(
&mut self,
_domain: String,
Expand Down Expand Up @@ -499,7 +499,7 @@ mod test {
super::Endpoint::Plain(Some(stream)) => stream,
#[cfg(feature = "rustls-tls")]
super::Endpoint::Secure(tls_stream) => tls_stream.get_ref().0,
#[cfg(feature = "native-tls")]
#[cfg(feature = "native-tls-tls")]
super::Endpoint::Secure(tls_stream) => tls_stream.get_ref().get_ref().get_ref(),
_ => unreachable!(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/io/tls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(any(feature = "native-tls", feature = "rustls"))]
#![cfg(any(feature = "native-tls-tls", feature = "rustls"))]

mod native_tls_io;
mod rustls_io;
2 changes: 1 addition & 1 deletion src/io/tls/native_tls_io.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "native-tls")]
#![cfg(feature = "native-tls-tls")]

use native_tls::{Certificate, TlsConnector};

Expand Down
41 changes: 23 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,18 @@
//! mysql_async = { version = "*", default-features = false, features = ["minimal"]}
//! ```
//!
//! **Note:* it is possible to use another `flate2` backend by directly choosing it:
//! * `minimal-rust` - same as `minimal` but rust-based flate2 backend is chosen. Enables:
//!
//! ```toml
//! [dependencies]
//! mysql_async = { version = "*", default-features = false }
//! flate2 = { version = "*", default-features = false, features = ["rust_backend"] }
//! ```
//! - `flate2/rust_backend`
//!
//! * `default` – enables the following set of crate's and dependencies' features:
//! * `default` – enables the following set of features:
//!
//! - `minimal`
//! - `native-tls-tls`
//! - `flate2/zlib"
//! - `mysql_common/bigdecimal03`
//! - `mysql_common/rust_decimal`
//! - `mysql_common/time03`
//! - `mysql_common/uuid`
//! - `mysql_common/frunk`
//! - `bigdecimal`
//! - `rust_decimal`
//! - `time`
//! - `frunk`
//! - `binlog`
//!
//! * `default-rustls` – same as default but with `rustls-tls` instead of `native-tls-tls`.
Expand Down Expand Up @@ -94,12 +89,19 @@
//! mysql_async = { version = "*", features = ["tracing"] }
//! ```
//!
//! * `derive` – enables `mysql_commom/derive` feature
//!
//! * `binlog` - enables binlog-related functionality. Enables:
//!
//! - `mysql_common/binlog"
//!
//! ### Proxied features
//!
//! * `derive` – enables `mysql_common/derive` feature
//! * `chrono` = enables `mysql_common/chrono` feature
//! * `time` = enables `mysql_common/time` feature
//! * `bigdecimal` = enables `mysql_common/bigdecimal` feature
//! * `rust_decimal` = enables `mysql_common/rust_decimal` feature
//! * `frunk` = enables `mysql_common/frunk` feature
//!
//! [myslqcommonfeatures]: https://github.com/blackbeam/rust_mysql_common#crate-features
//!
//! # TLS/SSL Support
Expand Down Expand Up @@ -464,10 +466,13 @@ pub use self::conn::Conn;
#[doc(inline)]
pub use self::conn::pool::Pool;

#[cfg(any(feature = "native-tls-tls", feature = "rustls-tls"))]
#[doc(inline)]
pub use self::error::tls::TlsError;

#[doc(inline)]
pub use self::error::{
tls::TlsError, DriverError, Error, IoError, LocalInfileError, ParseError, Result, ServerError,
UrlError,
DriverError, Error, IoError, LocalInfileError, ParseError, Result, ServerError, UrlError,
};

#[doc(inline)]
Expand All @@ -477,7 +482,7 @@ pub use self::query::QueryWithParams;
pub use self::queryable::transaction::IsolationLevel;

#[doc(inline)]
#[cfg(any(feature = "rustls", feature = "native-tls"))]
#[cfg(any(feature = "rustls", feature = "native-tls-tls"))]
pub use self::opts::ClientIdentity;

#[doc(inline)]
Expand Down
11 changes: 4 additions & 7 deletions src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mod native_tls_opts;
mod rustls_opts;

#[cfg(feature = "native-tls")]
#[cfg(feature = "native-tls-tls")]
pub use native_tls_opts::ClientIdentity;

#[cfg(feature = "rustls-tls")]
Expand All @@ -21,7 +21,6 @@ use url::{Host, Url};

use std::{
borrow::Cow,
convert::TryFrom,
fmt, io,
net::{Ipv4Addr, Ipv6Addr},
path::{Path, PathBuf},
Expand Down Expand Up @@ -117,13 +116,11 @@ impl HostPortOrUrl {

/// Represents data that is either on-disk or in the buffer.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
pub enum PathOrBuf<'a> {
Path(Cow<'a, Path>),
Buf(Cow<'a, [u8]>),
}

#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
impl<'a> PathOrBuf<'a> {
/// Will either read data from disk or return the buffered data.
pub async fn read(&self) -> io::Result<Cow<[u8]>> {
Expand Down Expand Up @@ -190,7 +187,7 @@ impl<'a> From<&'a [u8]> for PathOrBuf<'a> {
/// ```
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
pub struct SslOpts {
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#[cfg(any(feature = "native-tls-tls", feature = "rustls-tls"))]
client_identity: Option<ClientIdentity>,
root_certs: Vec<PathOrBuf<'static>>,
skip_domain_validation: bool,
Expand All @@ -199,7 +196,7 @@ pub struct SslOpts {
}

impl SslOpts {
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#[cfg(any(feature = "native-tls-tls", feature = "rustls-tls"))]
pub fn with_client_identity(mut self, identity: Option<ClientIdentity>) -> Self {
self.client_identity = identity;
self
Expand Down Expand Up @@ -241,7 +238,7 @@ impl SslOpts {
self
}

#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#[cfg(any(feature = "native-tls-tls", feature = "rustls-tls"))]
pub fn client_identity(&self) -> Option<&ClientIdentity> {
self.client_identity.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion src/opts/native_tls_opts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "native-tls")]
#![cfg(feature = "native-tls-tls")]

use std::borrow::Cow;

Expand Down
1 change: 0 additions & 1 deletion src/queryable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ impl Queryable for Transaction<'_> {

#[cfg(test)]
mod tests {
use super::Queryable;
use crate::{error::Result, prelude::*, test_misc::get_opts, Conn};

#[tokio::test]
Expand Down

0 comments on commit 976a527

Please sign in to comment.