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

Converge (just a little) the Stub and Serve traits #434

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

tikue
Copy link
Collaborator

@tikue tikue commented Feb 5, 2024

I don't think we'll ever completely unify these two traits, since one takes self by reference and one by value. However, we can actually get pretty close and have Serve + Clone types impl Stub. I don't remember the original motiviation of #251, but I think there are probably more use cases for services acting as Stubs than vice versa.

Fixes #251

This streamlines the Stub and Serve traits:

- Serve::method is removed
- Stub::call's request_name parameter is removed.

The tarpc-generated request types implement RequestName, and there are a
few convenience implementations for std types.
They now exist on an extension trait called RequestHook.
In an interesting twist, it turns out that all tarpc services can also
act as client stubs. This makes sense intuitively: a stub just sends a
request to a service and waits to receive a response; if you already
have a service, you can simply cut out the middleman.

I'm not really sure when this would be useful. Has science gone too far?
Maybe it could be used to more easily mock out backends in unit tests?
@tikue tikue added the Cleanup label Feb 5, 2024
@tikue tikue self-assigned this Feb 5, 2024
@tikue tikue added this pull request to the merge queue Feb 5, 2024
Merged via the queue into google:master with commit 403a633 Feb 5, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify Client and Serve traits
1 participant