Skip to main content

ProfileManager

Struct ProfileManager 

Source
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>

Source

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 profiles
  • target_name - Name of this profile target (e.g., “remotes”, “settings”)
  • storage - Storage backend to use for manifest
Source

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 directory
  • target_name - The name of the target (e.g. “settings”)
  • storage - Storage backend
  • enabled - Whether profiles are enabled
  • migrator - 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
Source

pub fn set_on_event<F>(&self, callback: F)
where F: Fn(ProfileEvent) + Send + Sync + 'static,

Set the event callback

§Arguments
  • callback - The callback function to be called when a profile event occurs
§Panics

Panics if the internal lock is poisoned.

Source

pub fn set_on_invalidate<F>(&self, callback: F)
where F: Fn() + Send + Sync + 'static,

Set the cache invalidation callback

§Arguments
  • callback - The callback function to be called when a profile switch occurs
§Panics

Panics if the internal lock is poisoned.

Source

pub fn invalidate_manifest(&self)

Invalidate the internal manifest cache

This forces the manifest to be re-read from disk on the next access.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn profile_path(&self, name: &str) -> PathBuf

Get the path to a specific profile’s directory

Source

pub fn active_path(&self) -> Result<PathBuf>

Get the path to the active profile’s directory

§Returns

Returns the path to the active profile’s directory.

§Errors

Returns an error if the manifest cannot be read.

Source

pub fn active(&self) -> Result<String>

Get the currently active profile name

§Returns

Returns the name of the currently active profile.

§Errors

Returns an error if the manifest cannot be read.

§Panics

This function will not panic under normal circumstances. The .unwrap() call is safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn list(&self) -> Result<Vec<String>>

List all profile names

§Returns

Returns a vector of profile names.

§Errors

Returns an error if the manifest cannot be read.

§Panics

This function will not panic under normal circumstances. The .unwrap() call is safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn exists(&self, name: &str) -> Result<bool>

Check if a profile exists

§Arguments
  • name - The name of the profile to check
§Returns

Returns true if the profile exists, false otherwise.

§Errors

Returns an error if the manifest cannot be read.

§Panics

This function will not panic under normal circumstances. The .unwrap() call is safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn create(&self, name: &str) -> Result<()>

Create a new profile

Creates an empty profile directory and updates the manifest.

§Arguments
  • name - The name of the profile to create
§Errors

Returns an error if the profile cannot be created.

§Panics

This function will not panic under normal circumstances. The .unwrap() calls are safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn switch(&self, name: &str) -> Result<()>

Switch to a different profile

Updates the active profile in the manifest and invalidates caches.

§Arguments
  • name - The name of the profile to switch to
§Errors

Returns an error if the profile cannot be switched.

§Panics

This function will not panic under normal circumstances. The .unwrap() calls are safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn delete(&self, name: &str) -> Result<()>

Delete a profile

Removes the profile directory and updates the manifest. Cannot delete the active profile or the last remaining profile.

§Arguments
  • name - The name of the profile to delete
§Errors

Returns an error if the profile cannot be deleted.

§Panics

This function will not panic under normal circumstances. The .unwrap() calls are safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn rename(&self, from: &str, to: &str) -> Result<()>

Rename a profile

§Arguments
  • from - The name of the profile to rename
  • to - The new name for the profile
§Errors

Returns an error if the profile cannot be renamed.

§Panics

This function will not panic under normal circumstances. The .unwrap() calls are safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

pub fn duplicate(&self, source: &str, target: &str) -> Result<()>

Duplicate a profile

Copies all contents from the source profile to a new profile.

§Arguments
  • source - The name of the source profile
  • target - The name of the target profile
§Errors

Returns an error if the profile cannot be duplicated.

§Panics

This function will not panic under normal circumstances. The .unwrap() calls are safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

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

Source

pub fn initialize_with_migration<F>(&self, detect_existing: F) -> Result<bool>
where F: FnOnce() -> 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 returns true if 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.

§Panics

Panics if the internal lock is poisoned.

Source

pub fn complete_migration(&self) -> Result<()>

Mark migration as complete and save manifest

§Errors

Returns an error if the manifest cannot be saved.

Source

pub fn manifest(&self) -> Result<ProfileManifest>

Get the manifest (for advanced use cases)

§Errors

Returns an error if the manifest cannot be read.

§Panics

This function will not panic under normal circumstances. The .unwrap() call is safe because ensure_manifest() is called first, which guarantees the manifest is populated.

Source

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> UnwindSafe for ProfileManager<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V