pub struct ConfigMigrator<'a> { /* private fields */ }Expand description
Struct that contains some configuration on how to migrate a config
let migrator = ConfigMigrator::new("version").with_default_version(0);
let (config, migration_occured) = migrator.migrate::<ConfigV2>(config_str).unwrap();Implementations§
Source§impl<'a> ConfigMigrator<'a>
impl<'a> ConfigMigrator<'a>
Sourcepub const fn new(version_key: &'a str) -> Self
pub const fn new(version_key: &'a str) -> Self
Creates a new ConfigMigrator using the provided key to find the version of the config
Sourcepub const fn with_default_version(self, default_version: i64) -> Self
pub const fn with_default_version(self, default_version: i64) -> Self
Adds a default version to use if it cannot be read from the config file
Sourcepub fn migrate_config<T: Migrate>(
&self,
config_str: &str,
) -> Result<(T, bool), Error>
pub fn migrate_config<T: Migrate>( &self, config_str: &str, ) -> Result<(T, bool), Error>
Handles the migration between versions of a configuration
On success, returns a tuple with the config and whether any migrations were performed. Errors if it could not read the version (and no default was provided), if the version failed to match any of the config structs, or if the config file failed to parse.
Auto Trait Implementations§
impl<'a> Freeze for ConfigMigrator<'a>
impl<'a> RefUnwindSafe for ConfigMigrator<'a>
impl<'a> Send for ConfigMigrator<'a>
impl<'a> Sync for ConfigMigrator<'a>
impl<'a> Unpin for ConfigMigrator<'a>
impl<'a> UnwindSafe for ConfigMigrator<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more