AppName

Struct AppName 

Source
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

Source

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:

  1. Validation: Checks if the application name has already been set
  2. Storage: Stores the name in a process-wide static variable using OnceLock
  3. 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 file

Examples:

  • 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 OnceLock for thread safety
  • Zero Runtime Overhead: Subsequent name resolution is a simple pointer dereference
  • Thread Safe: Uses OnceLock to ensure safe concurrent access
  • Memory Efficient: Stores only a single static string reference
§See Also
  • AppName::get() - Get the currently set application name
  • Config::path() - Determine configuration file path
  • Config::new() - Load configuration from disk
  • [directories::ProjectDirs] - Platform-specific directory handling
Source

pub fn get() -> &'static str

Get the effective application name.

Returns the runtime override if set, otherwise “aimx”.

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.

§

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

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