Skip to content
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

didc -t rs should implement serialize for records and variants #324

Closed
lastmjs opened this issue Mar 18, 2022 · 6 comments
Closed

didc -t rs should implement serialize for records and variants #324

lastmjs opened this issue Mar 18, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@lastmjs
Copy link
Contributor

lastmjs commented Mar 18, 2022

Is your feature request related to a problem? Please describe.

I am trying to use the generated Rust Candid types for use in Azle (TypeScript CDK), but I am running into this error when I try to have a record type as a parameter: the trait Serialize is not implemented for User`.

Describe the solution you'd like

For a simple Candid type like this:

type User = record {
  id: text;
};

The Rust code currently looks like this:

use ic_cdk::export::candid::{self, CandidType, Deserialize};
use ic_cdk::api::call::CallResult;

#[derive(CandidType, Deserialize)]
struct User { id: String }

It would be nice if Serialize could also be in the derive macro:

use ic_cdk::export::candid::{self, CandidType, Deserialize, Serialize};
use ic_cdk::api::call::CallResult;

#[derive(CandidType, Deserialize, Serialize)]
struct User { id: String }

Describe alternatives you've considered

This could also be set as a feature in Cargo.toml.

Additional context

It would be nice to have the option of configuring things like this on the types output by didc -t rust. I am happy to do a PR, though I believe this fix is probably pretty simple.

@chenyan-dfinity
Copy link
Contributor

We plan to add a config struct to control the generated code, similar to the protobuf builder: https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.type_attribute

@lastmjs
Copy link
Contributor Author

lastmjs commented Mar 18, 2022

Would this help when I am using didc -t rs? I will be using the command line or the Rust API.

@chenyan-dfinity
Copy link
Contributor

The CLI can take a config file as input, haven't thought about the format of the config file yet.

@lastmjs
Copy link
Contributor Author

lastmjs commented Mar 31, 2022

Could we also add an option to choose if nat outputs candid::Int or i128 and if int outputs candid::Nat or u128?

@chenyan-dfinity
Copy link
Contributor

Yep, all Candid types should be able to map to a user specified type.

ninegua pushed a commit to ninegua/candid that referenced this issue Apr 22, 2022
* adds typedoc to agent, configures for lerna

* wip: github action for release

* docs: improving agent-js README

* docs: copies licenses to packages and updates authentication README

* docs: adds homepage and keywords for npm

* chore: removes references to docs canisters

* chore: reverting browser in authentication package.json

* docs: lowercase keywords and docs deploy instructions

* adding links to hosted docs

* reverts release.yml and licenses.txt

* merge conflicts in package.json

* apache 2
@chenyan-dfinity
Copy link
Contributor

Duplicate of #255

@chenyan-dfinity chenyan-dfinity marked this as a duplicate of #255 May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants