Skip to content

Commit dae26b2

Browse files
authored
Dont generate connection_ids in the rust client. (#3004)
# Description of Changes This changes the behavior on the rust client, so that we let the server generate the connection id if the client hasn't called the unstable method to set a connection id. This is awkward for the `connection_id` function, since it now panics if the connection id hasn't been received from the server. We should deprecate this function in favor of a `try` version. This also changes the behavior of reusing the connection id if a client reconnects. The corresponding private PR is clockworklabs/SpacetimeDBPrivate#1921. # API and ABI breaking changes Technically not changing any API signatures, but this is behavior-changing, since the `connection_id` function can now panic. # Expected complexity level and risk 2. The risk here is people relying on that behavior. # Testing I think some tests need to be updated.
1 parent 5235082 commit dae26b2

File tree

408 files changed

+529
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

408 files changed

+529
-434
lines changed

crates/codegen/src/rust.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,9 @@ impl __sdk::DbContext for DbConnection {{
12721272
fn connection_id(&self) -> __sdk::ConnectionId {{
12731273
self.imp.connection_id()
12741274
}}
1275+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {{
1276+
self.imp.try_connection_id()
1277+
}}
12751278
}}
12761279
12771280
impl DbConnection {{
@@ -1588,6 +1591,9 @@ impl __sdk::DbContext for {struct_and_trait_name} {{
15881591
fn connection_id(&self) -> __sdk::ConnectionId {{
15891592
self.imp.connection_id()
15901593
}}
1594+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {{
1595+
self.imp.try_connection_id()
1596+
}}
15911597
}}
15921598
15931599
impl __sdk::{struct_and_trait_name} for {struct_and_trait_name} {{}}

crates/codegen/tests/snapshots/codegen__codegen_rust.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,9 @@ impl __sdk::DbContext for DbConnection {
18141814
fn connection_id(&self) -> __sdk::ConnectionId {
18151815
self.imp.connection_id()
18161816
}
1817+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
1818+
self.imp.try_connection_id()
1819+
}
18171820
}
18181821

18191822
impl DbConnection {
@@ -2027,6 +2030,9 @@ impl __sdk::DbContext for EventContext {
20272030
fn connection_id(&self) -> __sdk::ConnectionId {
20282031
self.imp.connection_id()
20292032
}
2033+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
2034+
self.imp.try_connection_id()
2035+
}
20302036
}
20312037

20322038
impl __sdk::EventContext for EventContext {}
@@ -2103,6 +2109,9 @@ impl __sdk::DbContext for ReducerEventContext {
21032109
fn connection_id(&self) -> __sdk::ConnectionId {
21042110
self.imp.connection_id()
21052111
}
2112+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
2113+
self.imp.try_connection_id()
2114+
}
21062115
}
21072116

21082117
impl __sdk::ReducerEventContext for ReducerEventContext {}
@@ -2175,6 +2184,9 @@ impl __sdk::DbContext for SubscriptionEventContext {
21752184
fn connection_id(&self) -> __sdk::ConnectionId {
21762185
self.imp.connection_id()
21772186
}
2187+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
2188+
self.imp.try_connection_id()
2189+
}
21782190
}
21792191

21802192
impl __sdk::SubscriptionEventContext for SubscriptionEventContext {}
@@ -2251,6 +2263,9 @@ impl __sdk::DbContext for ErrorContext {
22512263
fn connection_id(&self) -> __sdk::ConnectionId {
22522264
self.imp.connection_id()
22532265
}
2266+
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
2267+
self.imp.try_connection_id()
2268+
}
22542269
}
22552270

22562271
impl __sdk::ErrorContext for ErrorContext {}

crates/sdk/examples/quickstart-chat/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ fn creds_store() -> credentials::File {
6363
/// Our `on_connect` callback: save our credentials to a file.
6464
fn on_connected(_ctx: &DbConnection, _identity: Identity, token: &str) {
6565
if let Err(e) = creds_store().save(token) {
66-
eprintln!("Failed to save credentials: {:?}", e);
66+
eprintln!("Failed to save credentials: {e:?}");
6767
}
6868
}
6969

7070
// ### Handle errors and disconnections
7171

7272
/// Our `on_connect_error` callback: print the error, then exit the process.
7373
fn on_connect_error(_ctx: &ErrorContext, err: Error) {
74-
eprintln!("Connection error: {}", err);
74+
eprintln!("Connection error: {err}");
7575
std::process::exit(1);
7676
}
7777

7878
/// Our `on_disconnect` callback: print a note, then exit the process.
7979
fn on_disconnected(_ctx: &ErrorContext, err: Option<Error>) {
8080
if let Some(err) = err {
81-
eprintln!("Disconnected: {}", err);
81+
eprintln!("Disconnected: {err}");
8282
std::process::exit(1);
8383
} else {
8484
println!("Disconnected.");
@@ -166,14 +166,14 @@ fn print_message(ctx: &impl RemoteDbContext, message: &Message) {
166166
/// Our `on_set_name` callback: print a warning if the reducer failed.
167167
fn on_name_set(ctx: &ReducerEventContext, name: &String) {
168168
if let Status::Failed(err) = &ctx.event.status {
169-
eprintln!("Failed to change name to {:?}: {}", name, err);
169+
eprintln!("Failed to change name to {name:?}: {err}");
170170
}
171171
}
172172

173173
/// Our `on_send_message` callback: print a warning if the reducer failed.
174174
fn on_message_sent(ctx: &ReducerEventContext, text: &String) {
175175
if let Status::Failed(err) = &ctx.event.status {
176-
eprintln!("Failed to send message {:?}: {}", text, err);
176+
eprintln!("Failed to send message {text:?}: {err}");
177177
}
178178
}
179179

@@ -206,7 +206,7 @@ fn on_sub_applied(ctx: &SubscriptionEventContext) {
206206
/// Or `on_error` callback:
207207
/// print the error, then exit the process.
208208
fn on_sub_error(_ctx: &ErrorContext, err: Error) {
209-
eprintln!("Subscription failed: {}", err);
209+
eprintln!("Subscription failed: {err}");
210210
std::process::exit(1);
211211
}
212212

crates/sdk/examples/quickstart-chat/module_bindings/identity_connected_reducer.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/identity_disconnected_reducer.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/message_table.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/message_type.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/mod.rs

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/send_message_reducer.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/examples/quickstart-chat/module_bindings/set_name_reducer.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)