pub struct AppName;Expand description
Application name used for configuration paths.
Set once via AppName::set before accessing configuration. Defaults to
“aimx” if not overridden.
Implementations§
Source§impl AppName
impl AppName
Sourcepub fn set(name: &'static str)
pub fn set(name: &'static str)
Set the application name for configuration resolution.
Must be called before any configuration access.
§Panics
§Panics if called more than once.
§title: Set
Sets the application name for configuration resolution.
This function establishes the application name used to determine the configuration file location and directory structure. It must be called before any configuration access and can only be called once per process lifetime.
§Arguments
name- A static string slice specifying the application name. This name is used to construct the configuration file path and should be unique to your application.
§Errors
This function does not return an error but will panic if called more than once.
§Behavior
Internally, set() performs the following operations:
- Validation: Checks if the application name has already been set
- Storage: Stores the name in a process-wide static variable using
OnceLock - Path Resolution: The name is used by
Config::path()to determine the platform-specific configuration directory
§Side Effects
- Sets a global static variable that affects all subsequent configuration operations
- Determines the configuration file path for the entire process lifetime
- Once set, the application name cannot be changed
§Usage Pattern
Set the application name early in your application startup, before any configuration access:
use aimx::config::AppName;
// Set application name during initialization
AppName::set("my-aimx-app");
// Now you can safely access configuration
let config = aimx::config::get_config().unwrap();
println!("Workspace path: {}", config.workspace_path);§File Operations
The application name affects the configuration file location:
Platform-specific config directory/
└── {application_name}.toml # Configuration fileExamples:
- Windows:
%APPDATA%\Imogen\aimx\my-aimx-app.toml - macOS:
~/Library/Preferences/net.imogen.aimx/my-aimx-app.toml - Linux:
~/.config/aimx/my-aimx-app.toml
§Error Handling
The function uses a panic-based error handling strategy:
use aimx::config::AppName;
// First call succeeds
AppName::set("my-app");
// Second call will panic
// AppName::set("different-app"); // PANIC: App name can only be set once§Performance Considerations
- One-time Cost: The name is set only once using
OnceLockfor thread safety - Zero Runtime Overhead: Subsequent name resolution is a simple pointer dereference
- Thread Safe: Uses
OnceLockto ensure safe concurrent access - Memory Efficient: Stores only a single static string reference
§See Also
AppName::get()- Get the currently set application nameConfig::path()- Determine configuration file pathConfig::new()- Load configuration from disk- [
directories::ProjectDirs] - Platform-specific directory handling