#[post_upgrade]Expand description
Register the canister_post_upgrade entry point of a canister.
This attribute macro will export the function canister_post_upgrade
in the canister module.
The function under this attribute must have no return value.
Each canister can only have one canister_post_upgrade entry point.
§Example
#[post_upgrade]
fn post_upgrade_function() {
// ...
}§Argument
The post_upgrade function may accept an argument.
The argument must implement the CandidType trait.
And it should match the initialization parameters of the service constructor in the Candid interface. Therefore, the init function and the post_upgrade function should take the same argument type.
#[derive(Clone, Debug, CandidType, Deserialize)]
struct InitArg {
foo: u8,
}
#[post_upgrade]
fn post_upgrade_function(arg: InitArg) {
// ...
}In this case, the argument will be read from ic0.msg_arg_data_size/copy and passed to the
post_upgrade function upon successful deserialization.
§Custom Argument Decoding
You can specify a custom function to decode the arguments.
The function must take a Vec<u8> as an argument and return the same type as the post_upgrade arguments.
fn decode_args(arg_bytes: Vec<u8>) -> InitArg {
// ...
}
#[post_upgrade(decode_with = "decode_args")]
fn post_upgrade_function(arg: InitArg) {
// ...
}