Struct teloxide::prelude::DependencyMap
source · pub struct DependencyMap { /* private fields */ }
Expand description
A DI container with multiple dependencies.
This DI container stores types by their corresponding type identifiers. It cannot prove at compile-time that a type of a requested value exists within the container, so if you do not provide necessary types but they were requested, it will panic.
Examples
use dptree::di::{DependencyMap, DependencySupplier};
let mut container = DependencyMap::new();
container.insert(5_i32);
container.insert("abc");
assert_eq!(container.get(), Arc::new(5_i32));
assert_eq!(container.get(), Arc::new("abc"));
// If a type of a value already exists within the container, it will be replaced.
let old_value = container.insert(10_i32).unwrap();
assert_eq!(old_value, Arc::new(5_i32));
assert_eq!(container.get(), Arc::new(10_i32));
When a value is not found within the container, it will panic:
ⓘ
use dptree::di::{DependencyMap, DependencySupplier};
let mut container = DependencyMap::new();
container.insert(10i32);
container.insert(true);
container.insert("static str");
// thread 'main' panicked at 'alloc::string::String was requested, but not provided. Available types:
// &str
// bool
// i32
// ', /media/hirrolot/772CF8924BEBB279/Documents/Rust/dptree/src/di.rs:150:17
// note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
let string: Arc<String> = container.get();
Implementations§
source§impl DependencyMap
impl DependencyMap
pub fn new() -> DependencyMap
sourcepub fn insert<T>(&mut self, item: T) -> Option<Arc<T>>where
T: Send + Sync + 'static,
pub fn insert<T>(&mut self, item: T) -> Option<Arc<T>>where
T: Send + Sync + 'static,
Inserts a value into the container.
If the container do not has this type present, None
is returned.
Otherwise, the value is updated, and the old value is returned.
sourcepub fn insert_container(&mut self, container: DependencyMap)
pub fn insert_container(&mut self, container: DependencyMap)
Inserts all dependencies from another container into itself.
Trait Implementations§
source§impl Clone for DependencyMap
impl Clone for DependencyMap
source§fn clone(&self) -> DependencyMap
fn clone(&self) -> DependencyMap
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for DependencyMap
impl Debug for DependencyMap
source§impl Default for DependencyMap
impl Default for DependencyMap
source§fn default() -> DependencyMap
fn default() -> DependencyMap
Returns the “default value” for a type. Read more
source§impl<V> DependencySupplier<V> for DependencyMapwhere
V: Send + Sync + 'static,
impl<V> DependencySupplier<V> for DependencyMapwhere
V: Send + Sync + 'static,
source§impl PartialEq<DependencyMap> for DependencyMap
impl PartialEq<DependencyMap> for DependencyMap
source§fn eq(&self, other: &DependencyMap) -> bool
fn eq(&self, other: &DependencyMap) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.