Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement typed routes for ROUTER #365

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Implement typed routes for ROUTER #365

merged 2 commits into from
Oct 15, 2024

Conversation

simonwuelker
Copy link
Contributor

Implements ROUTER::add_typed_route, which (unlike ROUTER::add_route) knows about the type expected by the callback and makes it impossible to mismatch types between the receiver and the callback.

This method can be used pretty much exactly like ROUTER::add_route, I added a small test case that demonstrates this.

Closes #242

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great usability improvement! Thanks.

@jdm jdm enabled auto-merge October 15, 2024 02:35
@jdm jdm added this pull request to the merge queue Oct 15, 2024
Merged via the queue into servo:main with commit 59e248f Oct 15, 2024
17 checks passed
@mrobinson
Copy link
Member

This is a great usability improvement! Thanks.

Agreed! Unfortunately, add_route is a bit easy to use because of #239. Does it make sense to mark it as unsafe?

@simonwuelker simonwuelker deleted the typed-route branch October 15, 2024 09:53
@simonwuelker
Copy link
Contributor Author

simonwuelker commented Oct 15, 2024

Agreed! Unfortunately, add_route is a bit easy to use because of #239. Does it make sense to mark it as unsafe?

unsafe is usually reserved for functions that can cause undefined behavior if used incorrectly, and I don't think add_route can quite do that.

Perhaps a
#[deprecated(since="0.18.4", note="please use 'add_typed_route' instead")]
annotation would be more appropriate?

@simonwuelker
Copy link
Contributor Author

Hmm, perhaps I should have implemented the callback to receive a Result<T, Error> instead.
Functions like servo's route_ipc_receiver_to_new_crossbeam_receiver_preserving_errors need to know about any errors that occured, because constellation is not allowed to crash.

I'll make a follow-up PR once we have decided whether to mark add_route as unsafe/deprecated.

@jdm
Copy link
Member

jdm commented Oct 15, 2024

Agreed that deprecated feels more appropriate here than unsafe. If there isn't a way to trigger memory unsafety, unsafe would be overkill.

@mrobinson
Copy link
Member

I guess since serializable types cannot contain pointers, it is not possible to create memory unsafety with this issue. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Typed Version of add_route.
3 participants