rust-sdk icon indicating copy to clipboard operation
rust-sdk copied to clipboard

Proc macros to reduce boiler plate

Open NickLarsenNZ opened this issue 2 years ago • 5 comments

Dapr seems quite easy to get going in other languages that provide annotations/attributes. I think the same should be done for the Rust SDK.

For example:

[Topic("pubsub", "orders")]
[HttpPost("/checkout")]
public async Task<ActionResult<Order>>Checkout(Order order, [FromServices] DaprClient daprClient)
{
    // Logic
    return order;
}

Could be expressed as:

#[topic(pub_sub_name = "pubsub", topic = "orders")]
#[post("/checkout")]
async fn hello(order: Order) -> String {
    format!("Order id: {}", order.id)
}

Am I right in thinking that the difficulty comes in the variety of HTTP server crates? Or is that quite decoupled from decorating the handler?

NickLarsenNZ avatar Sep 20 '22 20:09 NickLarsenNZ

Maybe it doesn't even need to consider HTTP handlers. It could just be a standalone event handler.

NickLarsenNZ avatar Sep 20 '22 21:09 NickLarsenNZ

@NickLarsenNZ I have added a PR for the Procedural Macro for the pub sub topic.

https://github.com/dapr/rust-sdk/pull/87

zedgell avatar Jan 01 '23 10:01 zedgell

Nice one @zedgell

NickLarsenNZ avatar Jan 01 '23 11:01 NickLarsenNZ

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted) or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 19 '24 21:05 github-actions[bot]

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue or help wanted. Thank you for your contributions.

github-actions[bot] avatar May 26 '24 21:05 github-actions[bot]