Skip to content

Commit ef71e87

Browse files
committed
more progress tidying up feature flags
1 parent 4227a3e commit ef71e87

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;
@@ -356,12 +360,20 @@ fn write_escaped_quoted(output: &mut Vec<u8>, s: &str) {
356360
write_escaped_impl(must_escape_quoted, |output| output.push(b'"'), output, s)
357361
}
358362

359-
enum Connection {
363+
#[cfg(feature = "sync-sender-tcp")]
364+
enum SyncConnection {
360365
Direct(Socket),
361366
Tls(Box<StreamOwned<ClientConnection, Socket>>),
362367
}
363368

364-
impl Connection {
369+
#[cfg(feature = "async-sender-tcp")]
370+
enum AsyncConnection {
371+
Direct(tokio::net::TcpStream),
372+
Tls(Box<tokio_rustls::client::TlsStream<tokio::net::TcpStream>>),
373+
}
374+
375+
#[cfg(feature = "sync-sender-tcp")]
376+
impl SyncConnection {
365377
fn send_key_id(&mut self, key_id: &str) -> Result<()> {
366378
writeln!(self, "{}", key_id)
367379
.map_err(|io_err| map_io_to_socket_err("Failed to send key_id: ", io_err))?;
@@ -425,16 +437,22 @@ impl Connection {
425437
}
426438
}
427439

428-
#[cfg(any(feature = "sync-sender-tcp", feature = "sync-sender-http"))]
429440
enum ProtocolHandler {
430441
#[cfg(feature = "sync-sender-tcp")]
431-
Socket(Connection),
442+
SyncTcp(SyncConnection),
432443

433444
#[cfg(feature = "sync-sender-http")]
434-
Http(HttpHandlerState),
445+
SyncHttp(SyncHttpHandlerState),
446+
447+
#[cfg(feature = "async-sender-tcp")]
448+
AsyncTcp(AsyncConnection),
449+
450+
#[cfg(feature = "async-sender-http")]
451+
AsyncHttp()
435452
}
436453

437-
impl io::Read for Connection {
454+
#[cfg(feature = "sync-sender-tcp")]
455+
impl io::Read for SyncConnection {
438456
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
439457
match self {
440458
Self::Direct(sock) => sock.read(buf),
@@ -443,7 +461,8 @@ impl io::Read for Connection {
443461
}
444462
}
445463

446-
impl io::Write for Connection {
464+
#[cfg(feature = "sync-sender-tcp")]
465+
impl IoWrite for SyncConnection {
447466
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
448467
match self {
449468
Self::Direct(sock) => sock.write(buf),
@@ -1385,6 +1404,7 @@ impl Buffer {
13851404
}
13861405
}
13871406

1407+
#[cfg(feature = "_sync-sender")]
13881408
/// Connects to a QuestDB instance and inserts data via the ILP protocol.
13891409
///
13901410
/// * To construct an instance, use [`Sender::from_conf`] or the [`SenderBuilder`].
@@ -1399,7 +1419,8 @@ pub struct Sender {
13991419
max_name_len: usize,
14001420
}
14011421

1402-
impl std::fmt::Debug for Sender {
1422+
#[cfg(feature = "_sync-sender")]
1423+
impl Debug for Sender {
14031424
fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
14041425
f.write_str(self.descr.as_str())
14051426
}
@@ -1873,7 +1894,7 @@ pub struct SenderBuilder {
18731894

18741895
tls_ca: ConfigSetting<CertificateAuthority>,
18751896
tls_roots: ConfigSetting<Option<PathBuf>>,
1876-
1897+
18771898
#[cfg(feature = "_sender-http")]
18781899
http: Option<HttpConfig>,
18791900
}
@@ -2365,6 +2386,7 @@ impl SenderBuilder {
23652386
Ok(self)
23662387
}
23672388

2389+
#[cfg(feature = "sync-sender-tcp")]
23682390
fn connect_tcp(&self, auth: &Option<AuthParams>) -> Result<ProtocolHandler> {
23692391
let addr: SockAddr = gai::resolve_host_port(self.host.as_str(), self.port.as_str())?;
23702392
let mut sock = Socket::new(Domain::IPV4, Type::STREAM, Some(SockProtocol::TCP))
@@ -2445,16 +2467,16 @@ impl SenderBuilder {
24452467
}
24462468
})?;
24472469
}
2448-
Connection::Tls(StreamOwned::new(tls_conn, sock).into())
2470+
SyncConnection::Tls(StreamOwned::new(tls_conn, sock).into())
24492471
}
2450-
None => Connection::Direct(sock),
2472+
None => SyncConnection::Direct(sock),
24512473
};
24522474

24532475
if let Some(AuthParams::Ecdsa(auth)) = auth {
24542476
conn.authenticate(auth)?;
24552477
}
24562478

2457-
Ok(ProtocolHandler::Socket(conn))
2479+
Ok(ProtocolHandler::SyncTcp(conn))
24582480
}
24592481

24602482
fn build_auth(&self) -> Result<Option<AuthParams>> {
@@ -2551,6 +2573,7 @@ impl SenderBuilder {
25512573
}
25522574
}
25532575

2576+
#[cfg(feature = "_sync-sender")]
25542577
/// Build the sender.
25552578
///
25562579
/// In the case of TCP, this synchronously establishes the TCP connection, and
@@ -2569,6 +2592,7 @@ impl SenderBuilder {
25692592
let auth = self.build_auth()?;
25702593

25712594
let handler = match self.protocol {
2595+
#[cfg(feature = "sync-sender-tcp")]
25722596
Protocol::Tcp | Protocol::Tcps => self.connect_tcp(&auth)?,
25732597
#[cfg(feature = "sync-sender-http")]
25742598
Protocol::Http | Protocol::Https => {
@@ -2630,7 +2654,7 @@ impl SenderBuilder {
26302654
self.host.deref(),
26312655
self.port.deref()
26322656
);
2633-
ProtocolHandler::Http(HttpHandlerState {
2657+
ProtocolHandler::SyncHttp(SyncHttpHandlerState {
26342658
agent,
26352659
url,
26362660
auth,
@@ -2648,7 +2672,7 @@ impl SenderBuilder {
26482672
Protocol::Tcp | Protocol::Tcps => ProtocolVersion::V1,
26492673
#[cfg(feature = "sync-sender-http")]
26502674
Protocol::Http | Protocol::Https => {
2651-
if let ProtocolHandler::Http(http_state) = &handler {
2675+
if let ProtocolHandler::SyncHttp(http_state) = &handler {
26522676
let settings_url = &format!(
26532677
"{}://{}:{}/settings",
26542678
self.protocol.schema(),
@@ -2843,6 +2867,7 @@ impl F64Serializer {
28432867
}
28442868
}
28452869

2870+
#[cfg(feature = "_sync-sender")]
28462871
impl Sender {
28472872
/// Create a new `Sender` instance from the given configuration string.
28482873
///
@@ -2913,7 +2938,7 @@ impl Sender {
29132938
return Ok(());
29142939
}
29152940
match self.handler {
2916-
ProtocolHandler::Socket(ref mut conn) => {
2941+
ProtocolHandler::SyncTcp(ref mut conn) => {
29172942
if transactional {
29182943
return Err(error::fmt!(
29192944
InvalidApiCall,
@@ -2926,7 +2951,7 @@ impl Sender {
29262951
})?;
29272952
}
29282953
#[cfg(feature = "sync-sender-http")]
2929-
ProtocolHandler::Http(ref state) => {
2954+
ProtocolHandler::SyncHttp(ref state) => {
29302955
if transactional && !buf.transactional() {
29312956
return Err(error::fmt!(
29322957
InvalidApiCall,

0 commit comments

Comments
 (0)