# Alloy\_sol\_macro but for candid

**URL:** <https://forum.dfinity.org/t/alloy-sol-macro-but-for-candid/40945>\
**Category:** Rust\
**Created:** [February 7, 2025, 8:05am UTC](https://forum.dfinity.org/t/alloy-sol-macro-but-for-candid/40945 "2025-02-07T08:05:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ulan](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ulan/32/2705_2.png) [@ulan](https://forum.dfinity.org/u/ulan)\
**Post date:** [February 7, 2025, 8:05am UTC](https://forum.dfinity.org/t/alloy-sol-macro-but-for-candid/40945/1 "2025-02-07T08:05:25Z")

</div>

Has anyone tried writing a Rust macro for candid that’s similar to `sol!` from [alloy\_sol\_macro](https://docs.rs/alloy-sol-macro/latest/alloy_sol_macro/)?

The idea would be to have something like:

```Rust
can!(
    icp_ledger,
    "../deps/candid/ryjl3-tyaaa-aaaaa-aaaba-cai.did"
);

```

And the macro creates a module `icp_ledger` that contains generated Rust from the given candid file. At the minimum it would generate types, but it could also provide canister objects with async methods corresponding to the endpoints (like js-agent and Motoko do). It could also have different call implementations depending on the compilation target such that it works both on-chain and off-chain.

I think it would greatly simplify programming in Rust for ICP by removing a lot of manual work.

I remember there was some work done in generating Rust from Candid, but I cannot find it anymore. All search results I see are about generation of Candid from Rust.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 7, 2025, 9:13am UTC](https://forum.dfinity.org/t/alloy-sol-macro-but-for-candid/40945/2 "2025-02-07T09:13:45Z")

</div>

Nice to see you again Ulan!

Do you know about [ic-cdk-bindgen](https://crates.io/crates/ic-cdk-bindgen)? It does almost that. I used it in [this project](https://github.com/bjoernek/multi_chain_voting/blob/main/src/backend/build.rs) if you want to see how it in action.

Maybe @lwshang can comment a bit more about the topic?

---

<div class="post-metadata">

**Author:** ![ulan](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ulan/32/2705_2.png) [@ulan](https://forum.dfinity.org/u/ulan)\
**Post date:** [February 7, 2025, 9:44am UTC](https://forum.dfinity.org/t/alloy-sol-macro-but-for-candid/40945/3 "2025-02-07T09:44:44Z")

</div>

Hello and thank a lot Severin!

Yep, that was the project I was remembering, but my google fu failed me.

I see that the project relies on build.rs and env variables for candid paths. I wonder if it’s possible to get the simplicity of `sol!` that can be placed into a regular Rust file without additional build steps/setup.

I will explore that direction (unless DFINITY is planning to do it).
