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

Candid to Rust binding #255

Open
5 tasks
chenyan-dfinity opened this issue Jun 30, 2021 · 1 comment · Fixed by #422
Open
5 tasks

Candid to Rust binding #255

chenyan-dfinity opened this issue Jun 30, 2021 · 1 comment · Fixed by #422
Labels
enhancement New feature or request

Comments

@chenyan-dfinity
Copy link
Contributor

chenyan-dfinity commented Jun 30, 2021

There is no one-to-one mapping between Candid and Rust types.

  • A candid type can map to multiple Rust types. For example, vec record { text; int } can map to Vec<(String, Int)>, HashMap<&str, Int>, or even &[Box<(Cow<str>, Arc<i128>)>].
  • The fundamental difference between Candid typing and Rust is structural typing vs nominal typing. That is, when you create a struct/enum type in Rust, you have to give the type a name, which doesn’t necessarily exist in the did file, or may not the best name you want. There’s also the question of what traits to derive for each struct.

As a starting point, we can generate a simple binding with default types and let the users to adjust the binding by hand. To automate the customization, we can design a builder similar to https://docs.rs/prost-build/0.7.0/prost_build/struct.Config.html

TODO:

  • design for config struct
  • handle management canister for agent target
  • detect if renaming collapse names
  • non-blocking call for agent
  • tests for golden files
@chenyan-dfinity chenyan-dfinity added the enhancement New feature or request label Jun 30, 2021
ninegua pushed a commit to ninegua/candid that referenced this issue Apr 22, 2022
* lerna.json enable authentication-demo

* fix lerna bootstrap -> prepare for authentication-demo
@frederikrothenberger
Copy link
Member

This is a very nice feature, that we're looking forward to using. 🙂

So far, the following issues are blockers for us:

  • The derived traits should be configurable (i.e usually we have Eq, PartialEq and Clone, Debug on our types because it's super handy in integration tests).
  • We use serde_bytes::ByteBuf for blob and not Vec<u8>. As pointed out above, we need finer grained control over the types chosen.

Not blockers but still useful things:

  • Our candid file contains documentation comments. It would be nice if they carried over to the generated rust types / stubs.
  • Stubs for the canister implementation would be useful to have a check that all canister methods were actually implemented.

CC: @przydatek

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

Successfully merging a pull request may close this issue.

2 participants