pub struct Config {
pub workspace_path: String,
pub last_path: String,
pub provider: String,
pub local: Provider,
pub external: Provider,
}Expand description
Application configuration structure
This struct contains all configuration settings for the AIM application, including session state and provider configurations for both local and external AI services.
Fields§
§workspace_path: StringPath to the workspace directory
This field persists the user’s workspace location to restore it on application startup. An empty string indicates no previous session.
last_path: StringPath to the last opened file or directory
This field persists the user’s last working location to restore it on application startup. An empty string indicates no previous session.
provider: StringCurrently selected provider identifier
Determines which provider configuration to use for AI requests. Valid values are “local” or “external”.
local: ProviderConfiguration for local AI provider
Contains settings for connecting to local AI services like Ollama, running on the user’s machine or local network.
external: ProviderConfiguration for external AI provider
Contains settings for connecting to external AI services like OpenAI or compatible APIs that require network access.
Implementations§
Source§impl Config
impl Config
Sourcepub fn get_instance() -> &'static RwLock<Self>
pub fn get_instance() -> &'static RwLock<Self>
Get the global singleton instance of the Config.
This method uses OnceLock to ensure thread-safe one-time initialization
of the configuration. The configuration is loaded from the config file
or created with defaults if no existing config exists.
Uses RwLock to allow multiple concurrent readers while ensuring
exclusive access during writes.
§Returns
Returns a reference to the RwLock-protected singleton Config instance.
Sourcepub fn read_lock() -> Result<RwLockReadGuard<'static, Self>, Box<dyn Error>>
pub fn read_lock() -> Result<RwLockReadGuard<'static, Self>, Box<dyn Error>>
Get a read lock on the Config for reading configuration values.
This is a convenience method that returns a read guard, allowing multiple concurrent readers without blocking each other.
§Returns
Returns a Result containing the read guard or an error if the lock is poisoned.
Sourcepub fn write_lock() -> Result<RwLockWriteGuard<'static, Self>, Box<dyn Error>>
pub fn write_lock() -> Result<RwLockWriteGuard<'static, Self>, Box<dyn Error>>
Get a write lock on the Config for writing configuration changes.
This is a convenience method that returns a write guard, providing exclusive access for modifying configuration values.
§Returns
Returns a Result containing the write guard or an error if the lock is poisoned.
Sourcepub fn new() -> Result<Self, Box<dyn Error>>
pub fn new() -> Result<Self, Box<dyn Error>>
Creates a new Config instance
This function attempts to load an existing configuration from the standard config directory. If no configuration exists or loading fails, it creates a new default configuration and saves it to disk.
§Returns
Ok(Config)- Successfully loaded or created configurationErr(Box<dyn std::error::Error>)- Failed to load or save configuration
§Examples
use aimx::{AppName, aim::Config};
AppName::set("app_test");
let config = Config::new().expect("Failed to create config");Sourcepub fn load() -> Result<Self, Box<dyn Error>>
pub fn load() -> Result<Self, Box<dyn Error>>
Loads configuration from the standard config directory
This function reads the TOML configuration file from the platform-specific configuration directory and deserializes it into an Config struct.
§Returns
Ok(Config)- Successfully loaded configurationErr(Box<dyn std::error::Error>)- Failed to load or parse configuration
§Errors
This function will return an error if:
- The configuration file cannot be read from disk
- The configuration file is not valid TOML
- The configuration file structure doesn’t match Config
Sourcepub fn save(&self) -> Result<(), Box<dyn Error>>
pub fn save(&self) -> Result<(), Box<dyn Error>>
Saves the configuration to the standard config directory
Serializes the configuration to TOML format and writes it to the platform-specific configuration directory. Creates any necessary parent directories.
§Returns
Ok(())- Successfully saved configurationErr(Box<dyn std::error::Error>)- Failed to save configuration
§Errors
This function will return an error if:
- The configuration directory cannot be created
- The configuration file cannot be written to disk
- Serialization to TOML fails
§Examples
use aimx::{AppName, aim::Config};
AppName::set("app_test");
let mut config = Config::default();
config.last_path = "/path/to/my/project".to_string();
config.save().expect("Failed to save config");Sourcepub fn get_config_path() -> Result<PathBuf, Box<dyn Error>>
pub fn get_config_path() -> Result<PathBuf, Box<dyn Error>>
Gets the platform-specific configuration file path
Determines the appropriate configuration directory for the current platform and returns the full path to the config.toml file.
§Returns
Ok(PathBuf)- Path to the configuration fileErr(Box<dyn std::error::Error>)- Failed to determine config directory
§Platform-specific locations
- Linux:
~/.config/aimx/config.toml - macOS:
~/Library/Application Support/net.imogen.aimx/config.toml - Windows:
C:\Users\{username}\AppData\Roaming\imogen\aimx\config\config.toml
§Examples
use aimx::{AppName, aim::Config};
AppName::set("app_test");
let config_path = Config::get_config_path().expect("Failed to get config path");
println!("Config file location: {:?}", config_path);Sourcepub fn get_provider(&self) -> &Provider
pub fn get_provider(&self) -> &Provider
Gets the currently active provider configuration
Returns a reference to either the local or external provider based on
the provider field value.
§Returns
&Provider- Reference to the active provider configuration
§Selection logic
- If
provideris “external” → returns&self.external - Any other value → returns
&self.local(default behavior)
§Examples
use aimx::{AppName, aim::Config};
AppName::set("app_test");
let config = Config::new().expect("Failed to create config");
let provider = config.get_provider();
println!("Using API: {:?}", provider.api);
println!("Fast model: {}", provider.fast);Trait Implementations§
Source§impl Default for Config
impl Default for Config
Source§fn default() -> Self
fn default() -> Self
Creates a default configuration with sensible defaults
The default configuration sets up two providers:
- Local provider using Ollama with mistral:latest models
- External provider using OpenAI-compatible API with GPT models
§Returns
Returns a Config instance with default settings:
- No last opened path
- Local provider selected by default
- Standard capability level for both providers
- 30 second connection timeout
- 2 minute request timeout