Skip to main content

Config

Struct Config 

Source
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_callee to set it.
  • Dynamic callee: The canister ID is determined at runtime via ICP environment variable. Call Self::dynamic_callee to 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

Source

pub fn new<N, P>(canister_name: N, candid_path: P) -> Self
where N: Into<String>, P: Into<PathBuf>,

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.
Source

pub fn static_callee<S>(&mut self, canister_id: S) -> &mut Self
where S: Into<Principal>,

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
Source

pub fn dynamic_callee<S>(&mut self, env_var_name: S) -> &mut Self
where S: Into<String>,

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.
Source

pub fn set_type_selector_config<P>(&mut self, path: P) -> &mut Self
where P: Into<PathBuf>,

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.