Rust client SDK: rework EventContext
into multiple types
#2189
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
A repeated pain point with the post-0.12 client SDK API
has been excessive unnecessary pattern-matching or unwrapping
on the
ctx.event
within reducer callbacks.Previously, these had
ctx.event: Event
,with the type system not knowing that said
Event
would always beEvent::Reducer
.This was in a misguided attempt to reduce proliferation of context types.
As of this PR, we have different event context types for each category of callback,
which allows us to inform the type system precisely of the type of
event
.The event context types:
event: ReducerEvent<Reducer>
.event: ()
.event: Error
.Changes to callbacks:
DbConnectionBuilder::on_disconnect
now takesFnOnce(&ErrorContext)
.event: Error::Disconnected
.DisconnectContext
, which would likely also holdevent: Error
?DbConnectionBuilder::on_connect_error
now takesFnOnce(&ErrorContext)
.on_{reducer}
now takesFnMut(&ReducerEventContext, ...Args)
.SubscriptionBuilder::on_applied
andSubscriptionHandle::unsubscribe_then
now takeFnOnce(&SubscriptionEventContext)
.SubscriptionBuilder::on_error
now takesFnOnce(&ErrorContext)
.Notes for reviewers
Based on #2169 , which in turn is based on #2111 . Use the "show changes from all commits" dropdown in the upper-left of the review window to isolate this PR's changes, which start from
8234155a
.Most of this diff, linewise, is in autogenerated code, which you can largely or completely ignore.
Question
I have kept all the event context types having a field
ctx.event
(exceptSubscriptionEventContext
, which lacks any useful information to put there), of varying type. We could, alternatively, give this field a per-context name, likectx.error
forErrorContext
,ctx.reducer_event
forReducerEventContext
, and... well, actually those are the only two that would change.API and ABI breaking changes
Ayep, breaks the Rust client SDK API pretty comprehensibly. See
crates/sdk/examples/quickstart-chat/main.rs
for a sense of the changes.Expected complexity level and risk
1: The changes are essentially mechanical and do not change any semantics. Our codegen is extensively tested.
Testing