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
Auto Trait Implementations§
impl<S = JsonStorage> !Freeze for ProfileManager<S>
impl<S> RefUnwindSafe for ProfileManager<S>where
S: RefUnwindSafe,
impl<S> Send for ProfileManager<S>
impl<S> Sync for ProfileManager<S>
impl<S> Unpin for ProfileManager<S>where
S: Unpin,
impl<S> UnsafeUnpin for ProfileManager<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for ProfileManager<S>where
S: UnwindSafe,
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more