Skip to main content

ConfigStorage

Struct ConfigStorage 

Source
pub struct ConfigStorage {
    pub configurations: BTreeMap<String, Configuration>,
    pub claude_settings_dir: Option<String>,
    pub default_storage_mode: Option<StorageMode>,
}
Expand description

Storage manager for Claude API configurations

Handles persistence and retrieval of multiple API configurations stored in ~/.cc_auto_switch/configurations.json

Fields§

§configurations: BTreeMap<String, Configuration>

Map of alias names to configuration objects

§claude_settings_dir: Option<String>

Custom directory for Claude settings (optional)

§default_storage_mode: Option<StorageMode>

Default storage mode for writing configurations (None = use env mode)

Implementations§

Source§

impl ConfigStorage

Source

pub fn load() -> Result<Self>

Load configurations from disk

Reads the JSON file from ~/.claude/cc_auto_switch_setting.json Auto-migrates from old location ~/.cc-switch/configurations.json if it exists Returns default empty storage if file doesn’t exist

§Errors

Returns error if file exists but cannot be read or parsed

Source

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

Save configurations to disk

Writes the current state to ~/.claude/cc_auto_switch_setting.json Creates the directory structure if it doesn’t exist

§Errors

Returns error if directory cannot be created or file cannot be written

Source

pub fn migrate_from_old_path() -> Result<()>

Migrate configurations from old path to new path

Old path: ~/.cc_auto_switch/configurations.json New path: ~/.claude/cc_auto_switch_setting.json

Safe to run multiple times. If old path does not exist, returns Ok(()) and prints a note.

Source

pub fn add_configuration(&mut self, config: Configuration)

Add a new configuration to storage

§Arguments
  • config - Configuration object to add

Overwrites existing configuration with same alias

Source

pub fn remove_configuration(&mut self, alias_name: &str) -> bool

Remove a configuration by alias name

§Arguments
  • alias_name - Name of configuration to remove
§Returns

true if configuration was found and removed, false if not found

Source

pub fn get_configuration(&self, alias_name: &str) -> Option<&Configuration>

Get a configuration by alias name

§Arguments
  • alias_name - Name of configuration to retrieve
§Returns

Some(&Configuration) if found, None if not found

Source

pub fn set_claude_settings_dir(&mut self, directory: String)

Set the default directory for Claude settings

§Arguments
  • directory - Directory path for Claude settings
Source

pub fn get_claude_settings_dir(&self) -> Option<&String>

Get the current Claude settings directory

§Returns

Some(&String) if custom directory is set, None if using default

Source

pub fn update_configuration( &mut self, old_alias: &str, new_config: Configuration, ) -> Result<()>

Update an existing configuration

This method handles updating a configuration, including potential alias renaming. If the new configuration has a different alias name than the old one, it removes the old entry and creates a new one.

§Arguments
  • old_alias - Current alias name of the configuration to update
  • new_config - Updated configuration object
§Returns

Ok(()) if update succeeds, Err if the old configuration doesn’t exist

§Errors

Returns error if the configuration with old_alias doesn’t exist

Trait Implementations§

Source§

impl Default for ConfigStorage

Source§

fn default() -> ConfigStorage

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ConfigStorage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ConfigStorage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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, 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,