pub struct Config {
pub database_url: Option<String>,
pub default_queue: Option<String>,
pub default_limit: Option<u32>,
pub log_level: Option<String>,
pub connection_pool_size: Option<u32>,
}Expand description
CLI configuration structure.
This struct holds all configuration options for the Hammerwork CLI. Fields are optional to allow partial configuration and merging from multiple sources.
§Examples
use cargo_hammerwork::config::Config;
// Create configuration with defaults
let config = Config::default();
assert_eq!(config.get_default_limit(), 50);
assert_eq!(config.get_log_level(), "info");
assert_eq!(config.get_connection_pool_size(), 5);Fields§
§database_url: Option<String>Database connection URL (e.g., “postgresql://localhost/hammerwork”)
default_queue: Option<String>Default queue name for operations
default_limit: Option<u32>Default limit for list operations
log_level: Option<String>Log level (error, warn, info, debug, trace)
connection_pool_size: Option<u32>Database connection pool size
Implementations§
Source§impl Config
impl Config
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load configuration from file and environment variables.
Configuration is loaded with the following precedence:
- Environment variables (highest priority)
- Configuration file at
~/.config/hammerwork/config.toml - Default values (lowest priority)
§Examples
use cargo_hammerwork::config::Config;
let config = Config::load().expect("Failed to load configuration");
println!("Database URL: {:?}", config.database_url);Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Save configuration to file.
The configuration is saved to the platform-specific location:
- Linux/Mac:
~/.config/hammerwork/config.toml - Windows:
%APPDATA%\hammerwork\config.toml
§Examples
use cargo_hammerwork::config::Config;
let mut config = Config::default();
config.database_url = Some("postgresql://localhost/hammerwork".to_string());
config.save().expect("Failed to save configuration");pub fn get_database_url(&self) -> Option<&str>
pub fn get_default_queue(&self) -> Option<&str>
pub fn get_default_limit(&self) -> u32
pub fn get_log_level(&self) -> &str
pub fn get_connection_pool_size(&self) -> u32
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more