pub struct Options<T> { /* private fields */ }Expand description
Immutable options wrapper that implements IOptions<T>.
This struct holds an Arc<T> containing the final configured options snapshot.
Options are built once during container setup and remain immutable thereafter.
§Examples
use ferrous_di::{ServiceCollection, IOptions, Options, Resolver};
#[derive(Default)]
struct DatabaseConfig {
connection_string: String,
max_connections: u32,
}
let mut services = ServiceCollection::new();
services.add_options::<DatabaseConfig>()
.default_with(|| DatabaseConfig {
connection_string: "postgres://localhost".to_string(),
max_connections: 10,
})
.validate(|cfg| {
if cfg.max_connections == 0 {
Err("max_connections must be > 0".to_string())
} else {
Ok(())
}
})
.register();
let provider = services.build();
let config = provider.get_required::<Options<DatabaseConfig>>();
let db_config = config.get();
assert_eq!(db_config.max_connections, 10);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Options<T>
impl<T> RefUnwindSafe for Options<T>where
T: RefUnwindSafe,
impl<T> Send for Options<T>
impl<T> Sync for Options<T>
impl<T> Unpin for Options<T>
impl<T> UnwindSafe for Options<T>where
T: RefUnwindSafe,
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