pub struct ProfileManager<S: StorageBackend = JsonStorage> { /* private fields */ }Expand description
Manages profiles for a specific target (settings or sub-settings)
The ProfileManager handles:
- Creating, deleting, renaming, and duplicating profiles
- Switching the active profile
- Persisting the profile manifest
- Emitting events on profile changes
Implementations§
Source§impl<S: StorageBackend> ProfileManager<S>
impl<S: StorageBackend> ProfileManager<S>
Sourcepub fn new(base_dir: &Path, target_name: impl Into<String>, storage: S) -> Self
pub fn new(base_dir: &Path, target_name: impl Into<String>, storage: S) -> Self
Create a new profile manager for a given base directory
§Arguments
base_dir- The directory containing the profilestarget_name- Name of this profile target (e.g., “remotes”, “settings”)storage- Storage backend to use for manifest
Sourcepub fn initialize(
config_dir: &Path,
target_name: &str,
storage: S,
enabled: bool,
migrator: &ProfileMigrator,
) -> Result<(PathBuf, Option<Self>)>
pub fn initialize( config_dir: &Path, target_name: &str, storage: S, enabled: bool, migrator: &ProfileMigrator, ) -> Result<(PathBuf, Option<Self>)>
Initialize the profile manager, running migrations if enabled
This is a helper to centralize initialization logic that was previously in SettingsManager.
§Arguments
config_dir- The root configuration directorytarget_name- The name of the target (e.g. “settings”)storage- Storage backendenabled- Whether profiles are enabledmigrator- Migration strategy
§Returns
Returns a tuple of (active_settings_dir, Option<ProfileManager>).
If profiles are disabled, returns (config_dir, None).
§Errors
Returns an error if:
- Migration fails
- Profile manager initialization fails
- Active profile path cannot be resolved
Sourcepub fn set_on_event<F>(&self, callback: F)
pub fn set_on_event<F>(&self, callback: F)
Set the event callback
§Arguments
callback- The callback function to be called when a profile event occurs
Sourcepub fn set_on_invalidate<F>(&self, callback: F)
pub fn set_on_invalidate<F>(&self, callback: F)
Set the cache invalidation callback
§Arguments
callback- The callback function to be called when a profile switch occurs
Sourcepub fn invalidate_manifest(&self)
pub fn invalidate_manifest(&self)
Invalidate the internal manifest cache
This forces the manifest to be re-read from disk on the next access.
Sourcepub fn profile_path(&self, name: &str) -> PathBuf
pub fn profile_path(&self, name: &str) -> PathBuf
Get the path to a specific profile’s directory
Sourcepub fn active_path(&self) -> Result<PathBuf>
pub fn active_path(&self) -> Result<PathBuf>
Sourcepub fn rollback_to_flat(&self) -> Result<()>
pub fn rollback_to_flat(&self) -> Result<()>
Rollback to flat structure (removes all profiles except active)
§⚠️ Warning
This operation is irreversible and will:
- Keep only the active profile’s data
- Permanently delete all other profiles
- Remove the profile structure entirely
§Example
use rcman::{SettingsManager, SubSettingsConfig};
let manager = SettingsManager::builder("my-app", "1.0.0")
.with_sub_settings(SubSettingsConfig::new("remotes").with_profiles())
.build()?;
let remotes = manager.sub_settings("remotes")?;
// Remove profile support, keeping only active profile data
remotes.profiles()?.rollback_to_flat()?;§Errors
Returns an error if the rollback fails
Sourcepub fn initialize_with_migration<F>(&self, detect_existing: F) -> Result<bool>
pub fn initialize_with_migration<F>(&self, detect_existing: F) -> Result<bool>
Initialize profiles with auto-migration from flat structure
If files exist in the base directory but no manifest exists, moves them into a “default” profile.
§Arguments
detect_existing- A function that returnstrueif there are existing files to migrate
§Returns
Returns true if migration was needed, false otherwise.
§Errors
Returns an error if the manifest cannot be read or saved.
Sourcepub fn complete_migration(&self) -> Result<()>
pub fn complete_migration(&self) -> Result<()>
Mark migration as complete and save manifest
§Errors
Returns an error if the manifest cannot be saved.
Sourcepub fn manifest(&self) -> Result<ProfileManifest>
pub fn manifest(&self) -> Result<ProfileManifest>
Sourcepub fn profiles_dir(&self) -> &Path
pub fn profiles_dir(&self) -> &Path
Get the profiles directory path