There’s a tool called didc that you can use.
$ cat first_project.did
service : {
"greet": (text) -> (text) query;
}
USAGE:
didc bind <input> --target <target>
OPTIONS:
-t, --target <target> Specifies target language [possible values: js, ts, did, mo,
rs]
$ didc bind first_project.did --target mo
// This is a generated Motoko binding.
// Please use `import service "ic:canister_id"` instead to call canisters on the IC if possible.
module { public type Self = actor { greet : shared query Text -> async Text } }
$ didc bind first_project.did --target rs
// This is an experimental feature to generate Rust binding from Candid.
// You may want to manually adjust some of the types.
use ic_cdk::export::candid::{self, CandidType, Deserialize};
use ic_cdk::api::call::CallResult;
struct SERVICE(candid::Principal);
impl SERVICE{
pub async fn greet(&self, arg0: String) -> CallResult<(String,)> {
ic_cdk::call(self.0, "greet", (arg0,)).await
}
}