pub trait AnyContext{
// Provided method
fn value_as<T, Q>(&self, key: &Q) -> Option<&T>
where <Self::Entry as Entry>::KeyBorrowed: Borrow<Q>,
Q: Debug + Eq + Hash + ?Sized,
T: Any { ... }
}Expand description
The context where each entry’s value is a Box<DynAnyValue>.
Accessing the entry it contains and conveniently casting the result to a
concrete type can be done with the method offered by the AnyContext
trait.
For contexts implementing this trait, refer to the crate::context::map
module.
§Example
// `LiteralKeyAnyMapContext` implements `AnyContext`.
let mut context = LiteralKeyAnyMapContext::new();
context.insert_with::<BoxConverter, _, _>("error-code", 42i32);
context.insert_with::<BoxConverter, _, _>("cause", "unknown");
assert_eq!(context.value_as::<i32, _>("error-code"), Some(&42i32));
assert_eq!(context.value_as::<&str, _>("cause"), Some(&"unknown"));Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.