Type Alias UpgradeFunc

Source
pub type UpgradeFunc = fn(file: VersionedFile, initial_version: u8, upgraded_version: u8) -> Result<(), Error>;
Expand description

UpgradeFunc is a pointer to a function that upgrades a file from one version to the next. The intended starting and ending versions are explicitly stated in the input. When the upgrade is complete, the file cursor will automatically be placed back at the start of the file.

It may seem rather redundant to explicitly declare the version transition in the input to the UpgradeFunc, as the version numbers are already stated multiple times elsewhere as well. Under normal circumstances, this redundancy would be seen as excessive, however a file upgrade has the potential to corrupt or destory data, so we want extra layers of protection to ensure that the wrong upgrade process is not called on a file.

This type is not usable until it has been wrapped with wrap_upgrade_process. UpgradeFunc defines the signature for a function that can be used to upgrade a VersionedFile. The UpgradeFunc function will receive the file that needs to be upgraded, and it will also receive the intended initial version and upgraded version. The version inputs allow the upgrade function to double check that the right upgrade is being used - if a bug in the library somehow causes the wrong upgrade to be used, the user may end up with corrupted data. For that reason, we place extra redundancy around the version checks.

UpgradeFunc functions cannot be used directly due to Rust’s current inability to support async function pointers. To use an UpgradeFunc, one must call wrap_upgrade_process first.