As a developer, I want to be able to customize the code generated by didc so that I don't have to do so with a sed script.
Is your feature request related to a problem? Please describe. Currently I have to post-process the Rust code generated by .didc. The changes include:
- Make types and their fields public, otherwise they cannot be used!
- Comment out the header; I often use different imports and need different clippy rules.
- Customize the list of traits applied to every struct.
- ... and many other things.
Describe the solution you'd like Rather than making a huge long list of customizations, I would like to suggest that to start with we introduce a structure for managing customizations.
In particular I would like to propose an options file that could be called like this:
didc bind --target rs --options optfile.did somefile.candid
or
didc bind --target rs --options <( echo stuff) somefile.candid
That options file could then, for example, contain record{ rust = record {header=false}} to suppress printing the Rust header.
Describe alternatives you've considered
- Having a bunch of flags. I think this could get unwieldy.
- Having an implicit location for an options file. We could do this but then we would still want an override.
Additional context
Note: If approved in principle I would be happy to implement this and then make further proposals, one for every option.
We are certainly working on this direction! Note that there is an ruditemary Config option for Rust codegen: https://github.com/dfinity/candid/blob/master/rust/candid/src/bindings/rust.rs#L16. It's not exposed in didc yet, as I feel it's not mature enough.
Make types and their fields public, otherwise they cannot be used!
This should already be fixed in the latest didc.
Customize the list of traits applied to every struct.
There is a config option to do this already.
Cool, thank you for the information. I'll look at the latest didc and give it a spin.
Would it be an option to expose the config option via a hidden flag? Hidden in the sense that didc --help does not show it? That way we can test the config in some real-world use cases without committing to it? Regardless, please consider us as willing testers for this!
@chenyan-dfinity Regarding pub, it looks as if fields are still private for didc version 0.3.5:
max@sinkpad:~/dfn/nns-dapp/branches/no-pub-no-more (7:21)$ didc --version
didc 0.3.5
max@sinkpad:~/dfn/nns-dapp/branches/no-pub-no-more (7:37)$ didc bind --target rs declarations/sns_ledger/sns_ledger.did | grep -A5 -m1 struct
pub struct Account { owner: Principal, subaccount: Option<Subaccount> }
^ owner is private
Are they pub on an unreleased head of main? Let me check.... Yes, head of master works. I'll wait for your next release! :-)
I think the latest release already has this: https://github.com/dfinity/candid/releases/tag/2023-09-27. I'm bad at bumping versions, didc may still report version 0.3.5 for the new release :(