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 an easier way to get Send Serve and Stub #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevefan1999-personal
Copy link
Contributor

This PR improves upon #475 by observing trait-variant output and closely imitating the behavior without major breaking changes. There is no need to fill in a lot of unnecessary Send Sync bounds after this which clogged up in the original idea for #475 by using a downgrade trick using extension trait. All existing codes including the examples and the tests compiles without any changes.


/// A connection to a remote service.
/// Calls the service with requests of type `Req` and receives responses of type `Resp`.
pub trait SendStub: Send {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to use return-type notation to avoid duplicating the trait definition? rust-lang/rust#129629

pub trait SendStub: Stub + Send where <Self as Stub>::call(..): Send {}

impl<S: Stub + Send> SendStub for S where <S as Stub>::call(..): Send {}

Benefits of doing it this way:

  • The implementations for Channel and Serve don't need to be duplicated
  • the trait method can still be an async fn.

I think the same trick can also be applied to Serve and the proc macro-generated service trait.

Of course, the downside is this is still an experimental feature. But I think I'd rather think about solving this in a forward-thinking way. We can add a feature gate for it here, as well, so that it's only enabled if compiled with a tarpc Cargo feature that enables unstable features.

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.

2 participants