# Generate did file automatically

**URL:** <https://forum.dfinity.org/t/generate-did-file-automatically/16033>\
**Category:** Rust\
**Created:** [October 21, 2022, 7:25am UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033 "2022-10-21T07:25:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [October 21, 2022, 7:25am UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/1 "2022-10-21T07:25:32Z")

</div>

Is there a way to generate automatically the `did` file for the public query and update functions and types in Rust - as in Motoko - or the did file should really be edited manually?

---

<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:** [October 21, 2022, 7:39am UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/2 "2022-10-21T07:39:57Z")

</div>

@lwshang you’re working on this right now. What’s the current best practice?

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [October 21, 2022, 3:30pm UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/3 "2022-10-21T15:30:22Z")

</div>

Hi @peterparker,

We currently don’t have a clean way to auto generate candid for rust canister.

While there is a workaround as described in this post:

> [@Automatic generation of Candid from Rust](https://forum.dfinity.org/t/automatic-generation-of-candid-from-rust/14627/2):
>
> Hey yeah we’ve been able to generate candid from rust for a while now. Not sure why it’s still kinda hidden from documentation. All the psychedelic projects use it ! You just need to add the CandidType derive, and the candid\_service(query/update/init) macro to all the methods and types that need to be exported. Then, the export\_service!() macro will generate function that returns the candid from rust, which can be run differently depending on the project setup For projects using a main.rs: You…

The SDK team envisions a redesign of Rust CDK which can provide more ergonomic developer experience. Auto generating candid is one of the features we plan to provide. The work is still in early stage.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [October 21, 2022, 3:58pm UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/4 "2022-10-21T15:58:35Z")

</div>

Thanks for the feedback, looking forward to it then.

Workaround described in related post did not work out for me, I got an empty `service : {}` as outcome. Did not dig that deep in though.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 21, 2022, 11:22pm UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/5 "2022-10-21T23:22:35Z")

</div>

I suspect you also need to add this to the methods you’d like to include in the generated Candid:

```auto
use ic_cdk::export::candid::candid_method;

```

```auto
#[candid_method(query)]

```

```auto
#[candid_method(update)]

```

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [October 22, 2022, 6:55am UTC](https://forum.dfinity.org/t/generate-did-file-automatically/16033/6 "2022-10-22T06:55:52Z")

</div>

Good catch! The service gets filled.

```auto
type Asset = record { key : text; value : vec nat8 };
type State = record { owner : text; assets : vec record { text; Asset } };
service : { get : () -> (State) query }

```

Thanks!
