Skip to content

Commit 70d044f

Browse files
committed
more progress tidying up feature flags
1 parent c9557b7 commit 70d044f

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

questdb-rs/Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ chrono = { version = "0.4.40", optional = true }
3737
# the `ureq::unversioned` module which does not respect semantic versioning.
3838
ureq = { version = "3.0.10, <3.1.0", default-features = false, features = ["rustls-no-provider"], optional = true }
3939

40-
tokio = { version = "1.45.1", default-features = false, optional = true }
40+
tokio = { version = "1.45.1", default-features = false, features = ["net"], optional = true }
41+
tokio-rustls = { version = "0.26.2", default-features = false, optional = true }
4142
hyper = { version = "1.6.0", default-features = false, optional = true }
4243

4344
serde_json = { version = "1", optional = true }
@@ -68,16 +69,16 @@ default = ["sync-sender", "tls-webpki-certs", "ring-crypto"]
6869
sync-sender = ["sync-sender-tcp", "sync-sender-http"]
6970

7071
# Sync ILP/TCP
71-
sync-sender-tcp = ["_sender-tcp"]
72+
sync-sender-tcp = ["_sync-sender", "_sender-tcp"]
7273

7374
# Sync ILP/HTTP
74-
sync-sender-http = ["_sender-http", "dep:ureq", "dep:serde_json", "dep:rand"]
75+
sync-sender-http = ["_sync-sender", "_sender-http", "dep:ureq", "dep:serde_json", "dep:rand"]
7576

7677
# Async ILP/TCP + ILP/HTTP Sender
77-
async-sender = ["async-sender-tcp", "async-sender-http"]
78+
async-sender = ["_async-sender", "async-sender-tcp", "async-sender-http"]
7879

7980
# Async ILP/TCP Sender
80-
async-sender-tcp = ["_sender-tcp", "dep:tokio"]
81+
async-sender-tcp = ["_async-sender", "_sender-tcp", "dep:tokio", "dep:tokio-rustls"]
8182

8283
# Async ILP/HTTP Sender
8384
async-sender-http = ["_sender-http", "dep:tokio", "dep:hyper"]
@@ -109,6 +110,8 @@ chrono_timestamp = ["chrono"]
109110
# Hidden derived features, used in code to enable-disable code sections. Don't use directly.
110111
_sender-tcp = []
111112
_sender-http = []
113+
_sync-sender = []
114+
_async-sender = []
112115

113116
# The `aws-lc-crypto` and `ring-crypto` features are mutually exclusive,
114117
# thus compiling with `--all-features` will not work.

questdb-rs/src/ingress/http.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ impl Default for HttpConfig {
9595
}
9696
}
9797

98-
pub(super) struct HttpHandlerState {
98+
#[cfg(feature = "sync-sender-http")]
99+
pub(super) struct SyncHttpHandlerState {
99100
/// Maintains a pool of open HTTP connections to the endpoint.
100101
pub(super) agent: ureq::Agent,
101102

@@ -109,7 +110,8 @@ pub(super) struct HttpHandlerState {
109110
pub(super) config: HttpConfig,
110111
}
111112

112-
impl HttpHandlerState {
113+
#[cfg(feature = "sync-sender-http")]
114+
impl SyncHttpHandlerState {
113115
fn send_request(
114116
&self,
115117
buf: &[u8],
@@ -384,7 +386,7 @@ pub(super) fn parse_http_error(http_status_code: u16, response: Response<Body>)
384386

385387
#[allow(clippy::result_large_err)] // `ureq::Error` is large enough to cause this warning.
386388
fn retry_http_send(
387-
state: &HttpHandlerState,
389+
state: &SyncHttpHandlerState,
388390
buf: &[u8],
389391
request_timeout: Duration,
390392
retry_timeout: Duration,
@@ -417,7 +419,7 @@ fn retry_http_send(
417419

418420
#[allow(clippy::result_large_err)] // `ureq::Error` is large enough to cause this warning.
419421
pub(super) fn http_send_with_retries(
420-
state: &HttpHandlerState,
422+
state: &SyncHttpHandlerState,
421423
buf: &[u8],
422424
request_timeout: Duration,
423425
retry_timeout: Duration,
@@ -438,7 +440,7 @@ pub(super) fn http_send_with_retries(
438440
/// If the server does not support the `/settings` endpoint (404), it returns
439441
/// default values.
440442
pub(super) fn read_server_settings(
441-
state: &HttpHandlerState,
443+
state: &SyncHttpHandlerState,
442444
settings_url: &str,
443445
default_max_name_len: usize,
444446
) -> Result<(Vec<ProtocolVersion>, usize), Error> {
@@ -540,7 +542,7 @@ pub(super) fn read_server_settings(
540542

541543
#[allow(clippy::result_large_err)] // `ureq::Error` is large enough to cause this warning.
542544
fn retry_http_get(
543-
state: &HttpHandlerState,
545+
state: &SyncHttpHandlerState,
544546
url: &str,
545547
request_timeout: Duration,
546548
retry_timeout: Duration,
@@ -573,7 +575,7 @@ fn retry_http_get(
573575

574576
#[allow(clippy::result_large_err)] // `ureq::Error` is large enough to cause this warning.
575577
fn http_get_with_retries(
576-
state: &HttpHandlerState,
578+
state: &SyncHttpHandlerState,
577579
url: &str,
578580
request_timeout: Duration,
579581
retry_timeout: Duration,

questdb-rs/src/ingress/mod.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ use socket2::{Domain, Protocol as SockProtocol, SockAddr, Socket, Type};
3838
use std::collections::HashMap;
3939
use std::convert::Infallible;
4040
use std::fmt::{Debug, Display, Formatter, Write};
41-
use std::io::{self, BufRead, BufReader, ErrorKind, Write as IoWrite};
41+
use std::io::{self, BufReader, ErrorKind, Write as IoWrite};
42+
43+
#[cfg(feature = "sync-sender-tcp")]
44+
use std::io::BufRead;
45+
4246
use std::num::NonZeroUsize;
4347
use std::ops::Deref;
4448
use std::path::PathBuf;
@@ -350,12 +354,20 @@ fn write_escaped_quoted(output: &mut Vec<u8>, s: &str) {
350354
write_escaped_impl(must_escape_quoted, |output| output.push(b'"'), output, s)
351355
}
352356

353-
enum Connection {
357+
#[cfg(feature = "sync-sender-tcp")]
358+
enum SyncConnection {
354359
Direct(Socket),
355360
Tls(Box<StreamOwned<ClientConnection, Socket>>),
356361
}
357362

358-
impl Connection {
363+
#[cfg(feature = "async-sender-tcp")]
364+
enum AsyncConnection {
365+
Direct(tokio::net::TcpStream),
366+
Tls(Box<tokio_rustls::client::TlsStream<tokio::net::TcpStream>>),
367+
}
368+
369+
#[cfg(feature = "sync-sender-tcp")]
370+
impl SyncConnection {
359371
fn send_key_id(&mut self, key_id: &str) -> Result<()> {
360372
writeln!(self, "{}", key_id)
361373
.map_err(|io_err| map_io_to_socket_err("Failed to send key_id: ", io_err))?;
@@ -419,16 +431,22 @@ impl Connection {
419431
}
420432
}
421433

422-
#[cfg(any(feature = "sync-sender-tcp", feature = "sync-sender-http"))]
423434
enum ProtocolHandler {
424435
#[cfg(feature = "sync-sender-tcp")]
425-
Socket(Connection),
436+
SyncTcp(SyncConnection),
426437

427438
#[cfg(feature = "sync-sender-http")]
428-
Http(HttpHandlerState),
439+
SyncHttp(SyncHttpHandlerState),
440+
441+
#[cfg(feature = "async-sender-tcp")]
442+
AsyncTcp(AsyncConnection),
443+
444+
#[cfg(feature = "async-sender-http")]
445+
AsyncHttp()
429446
}
430447

431-
impl io::Read for Connection {
448+
#[cfg(feature = "sync-sender-tcp")]
449+
impl io::Read for SyncConnection {
432450
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
433451
match self {
434452
Self::Direct(sock) => sock.read(buf),
@@ -437,7 +455,8 @@ impl io::Read for Connection {
437455
}
438456
}
439457

440-
impl io::Write for Connection {
458+
#[cfg(feature = "sync-sender-tcp")]
459+
impl IoWrite for SyncConnection {
441460
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
442461
match self {
443462
Self::Direct(sock) => sock.write(buf),
@@ -1379,6 +1398,7 @@ impl Buffer {
13791398
}
13801399
}
13811400

1401+
#[cfg(feature = "_sync-sender")]
13821402
/// Connects to a QuestDB instance and inserts data via the ILP protocol.
13831403
///
13841404
/// * To construct an instance, use [`Sender::from_conf`] or the [`SenderBuilder`].
@@ -1393,7 +1413,8 @@ pub struct Sender {
13931413
max_name_len: usize,
13941414
}
13951415

1396-
impl std::fmt::Debug for Sender {
1416+
#[cfg(feature = "_sync-sender")]
1417+
impl Debug for Sender {
13971418
fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
13981419
f.write_str(self.descr.as_str())
13991420
}
@@ -1867,7 +1888,7 @@ pub struct SenderBuilder {
18671888

18681889
tls_ca: ConfigSetting<CertificateAuthority>,
18691890
tls_roots: ConfigSetting<Option<PathBuf>>,
1870-
1891+
18711892
#[cfg(feature = "_sender-http")]
18721893
http: Option<HttpConfig>,
18731894
}
@@ -2359,6 +2380,7 @@ impl SenderBuilder {
23592380
Ok(self)
23602381
}
23612382

2383+
#[cfg(feature = "sync-sender-tcp")]
23622384
fn connect_tcp(&self, auth: &Option<AuthParams>) -> Result<ProtocolHandler> {
23632385
let addr: SockAddr = gai::resolve_host_port(self.host.as_str(), self.port.as_str())?;
23642386
let mut sock = Socket::new(Domain::IPV4, Type::STREAM, Some(SockProtocol::TCP))
@@ -2439,16 +2461,16 @@ impl SenderBuilder {
24392461
}
24402462
})?;
24412463
}
2442-
Connection::Tls(StreamOwned::new(tls_conn, sock).into())
2464+
SyncConnection::Tls(StreamOwned::new(tls_conn, sock).into())
24432465
}
2444-
None => Connection::Direct(sock),
2466+
None => SyncConnection::Direct(sock),
24452467
};
24462468

24472469
if let Some(AuthParams::Ecdsa(auth)) = auth {
24482470
conn.authenticate(auth)?;
24492471
}
24502472

2451-
Ok(ProtocolHandler::Socket(conn))
2473+
Ok(ProtocolHandler::SyncTcp(conn))
24522474
}
24532475

24542476
fn build_auth(&self) -> Result<Option<AuthParams>> {
@@ -2545,6 +2567,7 @@ impl SenderBuilder {
25452567
}
25462568
}
25472569

2570+
#[cfg(feature = "_sync-sender")]
25482571
/// Build the sender.
25492572
///
25502573
/// In the case of TCP, this synchronously establishes the TCP connection, and
@@ -2563,6 +2586,7 @@ impl SenderBuilder {
25632586
let auth = self.build_auth()?;
25642587

25652588
let handler = match self.protocol {
2589+
#[cfg(feature = "sync-sender-tcp")]
25662590
Protocol::Tcp | Protocol::Tcps => self.connect_tcp(&auth)?,
25672591
#[cfg(feature = "sync-sender-http")]
25682592
Protocol::Http | Protocol::Https => {
@@ -2624,7 +2648,7 @@ impl SenderBuilder {
26242648
self.host.deref(),
26252649
self.port.deref()
26262650
);
2627-
ProtocolHandler::Http(HttpHandlerState {
2651+
ProtocolHandler::SyncHttp(SyncHttpHandlerState {
26282652
agent,
26292653
url,
26302654
auth,
@@ -2642,7 +2666,7 @@ impl SenderBuilder {
26422666
Protocol::Tcp | Protocol::Tcps => ProtocolVersion::V1,
26432667
#[cfg(feature = "sync-sender-http")]
26442668
Protocol::Http | Protocol::Https => {
2645-
if let ProtocolHandler::Http(http_state) = &handler {
2669+
if let ProtocolHandler::SyncHttp(http_state) = &handler {
26462670
let settings_url = &format!(
26472671
"{}://{}:{}/settings",
26482672
self.protocol.schema(),
@@ -2837,6 +2861,7 @@ impl F64Serializer {
28372861
}
28382862
}
28392863

2864+
#[cfg(feature = "_sync-sender")]
28402865
impl Sender {
28412866
/// Create a new `Sender` instance from the given configuration string.
28422867
///
@@ -2907,7 +2932,7 @@ impl Sender {
29072932
return Ok(());
29082933
}
29092934
match self.handler {
2910-
ProtocolHandler::Socket(ref mut conn) => {
2935+
ProtocolHandler::SyncTcp(ref mut conn) => {
29112936
if transactional {
29122937
return Err(error::fmt!(
29132938
InvalidApiCall,
@@ -2920,7 +2945,7 @@ impl Sender {
29202945
})?;
29212946
}
29222947
#[cfg(feature = "sync-sender-http")]
2923-
ProtocolHandler::Http(ref state) => {
2948+
ProtocolHandler::SyncHttp(ref state) => {
29242949
if transactional && !buf.transactional() {
29252950
return Err(error::fmt!(
29262951
InvalidApiCall,

0 commit comments

Comments
 (0)