# Generating did files in rust project , able to import types but not the method mentioned inside service section

**URL:** <https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936>\
**Category:** Rust\
**Tags:** Discussing\
**Created:** [November 28, 2024, 8:15pm UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936 "2024-11-28T20:15:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veercodeprog](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Veercodeprog](https://forum.dfinity.org/u/Veercodeprog)\
**Post date:** [November 28, 2024, 8:15pm UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936/1 "2024-11-28T20:15:21Z")

</div>

i generate the did files in frontend like:

> <https://github.com/Veercodeprog/upload-images-to-icp-asset/blob/main/src/canister/mod.rs>

did file :[upload-images-to-icp-asset/did/asset\_proxy.did at main · Veercodeprog/upload-images-to-icp-asset · GitHub](https://github.com/Veercodeprog/upload-images-to-icp-asset/blob/main/did/asset_proxy.did)

i am able to import the type like StoreArg from the did file:  
use crate::canister::asset\_proxy::StoreArg;

but not able to import the method like store from the did file using:  
use crate::canister::asset\_proxy::store;

---

<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:** [November 29, 2024, 4:59pm UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936/2 "2024-11-29T16:59:00Z")

</div>

I don’t know enough about these functions to make any solid suggestions. But in general we now suggest using `ic-cdk-bindgen` like [this](https://github.com/dfinity/cdk-rs/blob/main/examples/counter/src/inter_rs/build.rs) to generate canister bindings. Not sure it’s worth migrating for you, but maybe you want to have a look into that crate’s source

---

<div class="post-metadata">

**Author:** ![wiyota](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wiyota/32/27664_2.png) [@wiyota](https://forum.dfinity.org/u/wiyota)\
**Post date:** [November 30, 2024, 7:06am UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936/3 "2024-11-30T07:06:48Z")

</div>

In this use case, you cannot use `ic-cdk` because the code needs to be generated for the frontend, not within a canister.  
Therefore, you need a structure similar to the `Actor` in JavaScript, which contains an `ic-agent::Agent` instance and methods for interacting with canisters.

To achieve this, you can follow the source code of the `code_generator` in `ic-cdk-bindgen` and the `@dfinity/agent` library in JavaScript. However, considering the complexity, it would be better to separate this functionality into a dedicated library in the future, perhaps with a name like `ic-agent-bindgen`.

Alternatively, you can simply specify the method name as an argument when making calls with the `Agent`.

---

<div class="post-metadata">

**Author:** ![Veercodeprog](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Veercodeprog](https://forum.dfinity.org/u/Veercodeprog)\
**Post date:** [November 30, 2024, 3:18pm UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936/4 "2024-11-30T15:18:56Z")

</div>

i am doing a similar thing in a different project and it works fine .

> **[GitHub - Fuel-DAO/fuel-dao-frontend-rs](https://github.com/Fuel-DAO/fuel-dao-frontend-rs)**
>
> Contribute to Fuel-DAO/fuel-dao-frontend-rs development by creating an account on GitHub.

i have updated my project too where i am using Agent using ic\_auth\_client( a crate provided by @wiyota ) which works fine in the other project:

> **[GitHub - Veercodeprog/upload-images-to-icp-asset](https://github.com/Veercodeprog/upload-images-to-icp-asset)**
>
> Contribute to Veercodeprog/upload-images-to-icp-asset development by creating an account on GitHub.

i have also checked the build files inside target/…/out/…  
and the builds for candid files are generated correctly in my new project where i am struggling to import the methods from did file

@wiyota@Vivienne could you check please whats wrong in my project as it works in the other project .

---

<div class="post-metadata">

**Author:** ![Veercodeprog](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Veercodeprog](https://forum.dfinity.org/u/Veercodeprog)\
**Post date:** [November 30, 2024, 3:40pm UTC](https://forum.dfinity.org/t/generating-did-files-in-rust-project-able-to-import-types-but-not-the-method-mentioned-inside-service-section/37936/5 "2024-11-30T15:40:45Z")

</div>

@Vivienne @wiyota i fixed it  
i have to add mod canister in the main.rs in addition to lib.rs.  
Thanks for discussing it , 🌟
