Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed May 16, 2024
1 parent 577da30 commit 82ce2c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions tools/didc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ SUBCOMMANDS:
encode Encode Candid value
decode Decode Candid binary data
random Generate random Candid values
diff Diff two Candid values
```

## TOML config

`didc bind -t rs` and `didc random` can take a TOML file to configure how `didc` generate Rust binding or random values.

Rust bindgen can take an external Handlebar template with the following TOML file,

```toml
[didc.rust]
target = "custom" # Other targets: canister_call, agent, stub
template = "template.hbs" # required for custom target
# any tags mentioned from hbs
candid_crate = "candid"
service_name = "service"

[rust]
visibility = "pub(crate)"
attributes = "#[derive(CandidType, Deserialize, Debug)]"
GetBlocksResponse.attributes = "#[derive(CandidType, Deserialize, Debug, Clone, Serialize)]"
GetBlocksResponseArchivedBlocksItem.name = "ABetterName"
```

## Examples
Expand All @@ -41,10 +61,6 @@ $ didc decode '4449444c016d7c027c002a0301027d'
$ didc decode '4449444c016d7c027c002a0301027d' -t '(int)'
(42)
$ didc diff '(record{1;2;3}, 42)' '(record{1;5;9}, 42)'
record { edit { 1 put { 5 } }; edit { 2 put { 9 } }; }
skip
$ didc bind hello.did -t js
export const idlFactory = ({ IDL }) => {
return IDL.Service({ 'greet' : IDL.Func([IDL.Text], [IDL.Text], []) });
Expand All @@ -53,9 +69,9 @@ export const idlFactory = ({ IDL }) => {
$ didc random -t '(int, text)'
(-72_594_379_354_493_140_610_202_928_640_651_761_468, "_J`:t7^>")
$ didc random -t '(int, text)' -c '{ range = Some [-10, +10], text = "name" }'
$ didc random -t '(int, text)' -c 'random = { range = [-10, +10], text = "name" }'
(-6, "Cindy Klocko")
$ didc random -d service.did -m method -f random.dhall -a '("seed argument")' -l js
$ didc random -d service.did -m method -c random.toml -a '("seed argument")' -l js
[new BigNumber('-4'), 'Marcus Kris']
```
2 changes: 1 addition & 1 deletion tools/didc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn main() -> Result<()> {
"rs" => {
use candid_parser::bindings::rust::{compile, Config, ExternalConfig};
let external = configs
.get_subtable(&["external".to_string(), "rust".to_string()])
.get_subtable(&["didc".to_string(), "rust".to_string()])
.map(|x| x.clone().try_into().unwrap())
.unwrap_or(ExternalConfig::default());
let config = Config::new(configs);
Expand Down

0 comments on commit 82ce2c8

Please sign in to comment.