-
Notifications
You must be signed in to change notification settings - Fork 10
A more ergonomic macro #43
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
Comments
I think it's worth giving this a try, the macro could support both starting from the trait or starting from the struct impl. IIRC one reason I didn't go down this road is that I had some issues with the Futures |
I remember doing this in my Rust sdk prototype (Though not directly applicable here) Macros: https://github.com/h7kanna/restate-sdk-rust/blob/main/crates/derive/src/lib.rs#L224 |
Was it due to this lint:
The macro above could expand to something like this, skipping the traits altogether: pub struct MyService;
impl MyService {
async fn my_handler(
&self,
context: Context<'_>,
greeting: String,
) -> Result<String, HandlerError> {
todo!()
}
#[doc = r" Returns a serving function to use with [::restate_sdk::endpoint::Builder::with_service]."]
fn serve(self) -> ServeMyService {
ServeMyService {
service: Arc::new(self),
}
}
}
#[derive(Clone)]
pub struct ServeMyService {
service: Arc<MyService>,
}
impl Discoverable for ServeMyService {
/* */
}
impl Service for ServeMyService {
/* */
} Here, |
Fair enough, I think it makes sense to give a shot at this. The only rule though that I think it should apply is that when you annotate an |
Modify the procedural macros in ast.rs, gen.rs, and lib.rs to apply directly to impl blocks instead of traits, per Issue restatedev#43. This eliminates the need for separate trait definitions and simplifies the SDK's usage. New macro syntax examples: - #[restate_sdk::service] or #[restate_sdk::service(vis = "pub", name = "my_service")] - #[restate_sdk::object] or #[restate_sdk::object(vis = "pub")] - #[restate_sdk::workflow(name = "my_workflow")] - Method attributes: #[handler], #[handler(shared)], or #[handler(name = "my_handler")]
The Rust SDK currently forces you to write separate traits for all of your services, objects and workflows. I think it would be far more ergonomic to have the macro apply directly to the implementation body itself:
This also eliminates the awkward and non-idiomatic
FooBar
<->FooBarImpl
naming convention.What do you think of this approach?
The text was updated successfully, but these errors were encountered: