google / tarpc

An RPC framework for Rust with a focus on ease of use.
MIT License
3.09k stars 189 forks source link

Allow futures on Serve and Stub to be Send #448

Open ShaneMurphy2 opened 3 months ago

ShaneMurphy2 commented 3 months ago

Not sure if this approach is the right one, so this MR is a draft.

tikue commented 2 months ago

Sorry for the delay in reviewing! Will try to look in the next week.

ShaneMurphy2 commented 2 months ago

This looks like a reasonable change to me.

Perfect, that's what I was looking for by putting up an early draft.

Doesn't Serve need to be made a trait variant, too?

Probably, was just focusing on my use case a little too much 😅

Also, could you add some tests demonstrating how it will work for users?

Will do, as I mentioned this is an early draft to make sure the change makes sense.

ShaneMurphy2 commented 2 months ago

I'll get back to this in a day or so, thanks for the review!

ShaneMurphy2 commented 2 months ago

Haven't forgotten, just wrapped up in other stuff. I'll try to get to it soon!

ShaneMurphy2 commented 2 months ago

Looks like trait_variant::make doesn't support default implementations in trait definitions. I could update the macro in that crate, thoughts?

Also, how do you feel about renaming Serve and Stub to LocalServe and LocalStub so that the "default" type is Send, seems like the more common use case potentially.

ShaneMurphy2 commented 1 month ago

I've given it some more thought and I'm wondering if the right move is to instead have a feature flag that annotates all traits with async methods in them with async_trait. Thoughts @tikue?

tikue commented 2 weeks ago

I also just saw https://github.com/rust-lang/rfcs/pull/3654. Wonder how long it will take to be available on nightly?

ShaneMurphy2 commented 2 weeks ago

I also just saw rust-lang/rfcs#3654. Wonder how long it will take to be available on nightly?

Looks like even post-implementation the RFC still recommends the pattern provided by trait_variant: https://github.com/nikomatsakis/rfcs/blob/rtn/text/0000-return-type-notation.md#rtn-supports-convenient-trait-aliases https://github.com/nikomatsakis/rfcs/blob/rtn/text/0000-return-type-notation.md#guidelines-and-best-practices