pub struct Config { /* private fields */ }Expand description
Config for Candid to Rust bindings generation.
§Choose Bindgen Modes
The bindgen has following modes:
- Types only: Only the types definition will be generated. This is the default behavior with
Self::new. - Static callee: The canister ID is known at compile time. Call
Self::static_calleeto set it. - Dynamic callee: The canister ID is determined at runtime via ICP environment variable. Call
Self::dynamic_calleeto set it.
§Generate Bindings
After configuring your bindgen settings through the methods above, you must call
Self::generate to actually produce the Rust bindings.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new<N, P>(canister_name: N, candid_path: P) -> Self
pub fn new<N, P>(canister_name: N, candid_path: P) -> Self
Create a new Config instance.
§Arguments
canister_name- The name of the canister. This will be used as the generated file name. It is important to ensure that this name is valid for use in a file system (no spaces, special characters, or other characters that could cause issues with file paths).candid_path- The path to the Candid file.
Sourcepub fn static_callee<S>(&mut self, canister_id: S) -> &mut Self
pub fn static_callee<S>(&mut self, canister_id: S) -> &mut Self
Changes the bindgen mode to “Static callee”, where the canister ID is known at compile time.
This mode hardcodes the target canister ID in the generated code, making it suitable for deployments where the canister ID is fixed and known at compile time.
§Arguments
canister_id- The Principal ID of the target canister
Sourcepub fn dynamic_callee<S>(&mut self, env_var_name: S) -> &mut Self
pub fn dynamic_callee<S>(&mut self, env_var_name: S) -> &mut Self
Changes the bindgen mode to “Dynamic callee”, where the canister ID is determined at runtime.
This mode allows the canister ID to be resolved dynamically from an Internet Computer (ICP) environment variable, making it suitable for deployments where the target canister ID may change across environments.
§Arguments
env_var_name- The name of the ICP environment variable containing the canister ID.
Sourcepub fn set_type_selector_config<P>(&mut self, path: P) -> &mut Self
pub fn set_type_selector_config<P>(&mut self, path: P) -> &mut Self
Sets the path to the type selector configuration file.
The “type selector config” is a TOML file that specifies how certain Candid types should be mapped to Rust types (attributes, visibility, etc.). Please refer to the specification for more details.
Sourcepub fn generate(&self)
pub fn generate(&self)
Generate the bindings.
The generated bindings will be written to the output directory specified by the
OUT_DIR environment variable. The file will be named after the canister name.
For example, if the canister name is “my_canister”, the generated file will be
located at $OUT_DIR/my_canister.rs.