Struct Config

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

Path 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: String

Path 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: String

Currently selected provider identifier

Determines which provider configuration to use for AI requests. Valid values are “local” or “external”.

§local: Provider

Configuration for local AI provider

Contains settings for connecting to local AI services like Ollama, running on the user’s machine or local network.

§external: Provider

Configuration 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

Source

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.

Source

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.

Source

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.

Source

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 configuration
  • Err(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");
Source

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 configuration
  • Err(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
Source

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 configuration
  • Err(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");
Source

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 file
  • Err(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);
Source

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 provider is “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 Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

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

impl<'de> Deserialize<'de> for Config

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 PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Config

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

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,