pub struct ContextBuilder<M: ContextMarker> { /* private fields */ }Expand description
Builder for type-safe context configuration The builder is used to create a context with environment values and a default value.
§Example
use env_type::context::{ContextBuilder, ContextMarker};
use env_type::types::{EnvType};
struct TestContext;
impl ContextMarker for TestContext {
type Value = String;
}
let context = ContextBuilder::<TestContext>::default()
.with_value(EnvType::Dev, "dev".to_string())
.with_value(EnvType::Test, "test".to_string())
.with_default("default".to_string())
.build();
assert_eq!(context.get_for_env(&EnvType::Dev), Some("dev".to_string()));
assert_eq!(context.get_for_env(&EnvType::Test), Some("test".to_string()));
assert_eq!(context.get_for_env(&EnvType::Stg), Some("default".to_string()));Implementations§
Source§impl<M: ContextMarker> ContextBuilder<M>
ContextBuilder implementation
Create a new ContextBuilder with the environment values and default value.
impl<M: ContextMarker> ContextBuilder<M>
ContextBuilder implementation Create a new ContextBuilder with the environment values and default value.
pub fn with_value(self, env: EnvType, value: M::Value) -> Self
pub fn with_values<I>(self, envs: I, value: M::Value) -> Self
pub fn with_default(self, value: M::Value) -> Self
pub fn build(self) -> Context<M>
Trait Implementations§
Source§impl<M: ContextMarker> Default for ContextBuilder<M>
impl<M: ContextMarker> Default for ContextBuilder<M>
Auto Trait Implementations§
impl<M> Freeze for ContextBuilder<M>
impl<M> RefUnwindSafe for ContextBuilder<M>
impl<M> Send for ContextBuilder<M>
impl<M> Sync for ContextBuilder<M>
impl<M> Unpin for ContextBuilder<M>
impl<M> UnwindSafe for ContextBuilder<M>
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