Function canister_tools::post_upgrade

source ยท
pub fn post_upgrade<Data, OldData, F>(
    s: &'static LocalKey<RefCell<Data>>,
    memory_id: MemoryId,
    opt_old_as_new_convert: Option<F>
)
where Data: 'static + Serializable, OldData: Serializable, F: Fn(OldData) -> Data,
Expand description

Call this function in the post_upgrade_hook. Deserializes the data stored at the memory_id and loads it onto the global variable. Then registers the global variable with the memory_id for the next upgrade and for the state-snapshots.

Use the opt_old_as_new_convert parameter to specify a function that converts an old data structure into a new one. This is useful when changing the type of the data structure through an upgrade. The function will deserialize the data into the old data structure type, then convert it into the new data structure type, and then load it onto the global variable.