pub struct Context<M: ContextMarker> { /* private fields */ }Expand description
Context is Generic context container The context is a key-value store for environment values.
Implementations§
Source§impl<M: ContextMarker> Context<M>
impl<M: ContextMarker> Context<M>
Sourcepub fn get_for_env(&self, env: &EnvType) -> Option<M::Value>
pub fn get_for_env(&self, env: &EnvType) -> Option<M::Value>
Get the value for the current environment If no value is found, return the default value(optional)
Trait Implementations§
Source§impl<M: ContextMarker> Default for Context<M>
Context implementation for ContextMarker
impl<M: ContextMarker> Default for Context<M>
Context implementation for ContextMarker
§Example
use env_type::context::{ContextMarker, Context};
use env_type::types::EnvType;
struct TestContext;
impl ContextMarker for TestContext {
type Value = String;
}
let mut context = Context::<TestContext>::default();
assert!(context.get_for_env(&EnvType::Dev).is_none());Auto Trait Implementations§
impl<M> Freeze for Context<M>
impl<M> RefUnwindSafe for Context<M>
impl<M> Send for Context<M>
impl<M> Sync for Context<M>
impl<M> Unpin for Context<M>
impl<M> UnwindSafe for Context<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