Skip to content

Commit ad01a9e

Browse files
authored
Rust SDK: Make confirmed parameter optional (#3283)
For consistency with [TypeScript] and [C#]. If `DbConnectionBuilder::with_confirmed_reads` is not called, don't set the parameter on the connection URL, so that the server can choose the default. [TypeScript]: #3247 [C#]: #3282 # Expected complexity level and risk 1
1 parent 4521487 commit ad01a9e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

sdks/rust/src/db_connection.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,10 @@ but you must call one of them, or else the connection will never progress.
975975
/// Note that enabling confirmed reads will increase the latency between a
976976
/// reducer call and the corresponding subscription update arriving at the
977977
/// client.
978+
///
979+
/// If this method is not called, the server chooses the default.
978980
pub fn with_confirmed_reads(mut self, confirmed: bool) -> Self {
979-
self.params.confirmed = confirmed;
981+
self.params.confirmed = Some(confirmed);
980982
self
981983
}
982984

sdks/rust/src/websocket.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ fn parse_scheme(scheme: Option<Scheme>) -> Result<Scheme, UriError> {
107107
pub(crate) struct WsParams {
108108
pub compression: Compression,
109109
pub light: bool,
110-
/// `true` to enable confirmed reads for the connection.
111-
pub confirmed: bool,
110+
/// `Some(true)` to enable confirmed reads for the connection,
111+
/// `Some(false)` to disable them.
112+
/// `None` to not set the parameter and let the server choose.
113+
pub confirmed: Option<bool>,
112114
}
113115

114116
fn make_uri(host: Uri, db_name: &str, connection_id: Option<ConnectionId>, params: WsParams) -> Result<Uri, UriError> {
@@ -155,8 +157,9 @@ fn make_uri(host: Uri, db_name: &str, connection_id: Option<ConnectionId>, param
155157
}
156158

157159
// Enable confirmed reads if requested.
158-
if params.confirmed {
159-
path.push_str("&confirmed=true");
160+
if let Some(confirmed) = params.confirmed {
161+
path.push_str("&confirmed=");
162+
path.push_str(if confirmed { "true" } else { "false" });
160163
}
161164

162165
parts.path_and_query = Some(path.parse().map_err(|source: InvalidUri| UriError::InvalidUri {

0 commit comments

Comments
 (0)