Use Strings in context values map
This commit is contained in:
parent
f02e12c63a
commit
e89ebb2c79
1 changed files with 9 additions and 3 deletions
|
@ -17,7 +17,13 @@ pub struct Context {
|
||||||
// Wether or not this context is cancelled.
|
// Wether or not this context is cancelled.
|
||||||
cancelled: Arc<AtomicBool>,
|
cancelled: Arc<AtomicBool>,
|
||||||
// A collection of read only values stored in this context.
|
// A collection of read only values stored in this context.
|
||||||
values: Option<HashMap<&'static str, Box<dyn Any + Send + Sync>>>,
|
values: Option<HashMap<String, Box<dyn Any + Send + Sync>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Context {
|
||||||
|
fn default() -> Self {
|
||||||
|
Context::background()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
@ -74,7 +80,7 @@ impl Context {
|
||||||
|
|
||||||
// Add a value to the context. It overwrites any previously set values
|
// Add a value to the context. It overwrites any previously set values
|
||||||
// with the same key.
|
// with the same key.
|
||||||
pub fn add_value<V>(&mut self, key: &'static str, value: V)
|
pub fn add_value<V>(&mut self, key: String, value: V)
|
||||||
where
|
where
|
||||||
V: Any + Send + Sync + Sized,
|
V: Any + Send + Sync + Sized,
|
||||||
{
|
{
|
||||||
|
@ -148,7 +154,7 @@ impl Context {
|
||||||
|
|
||||||
// Get a value from the context. If no value is stored under the
|
// Get a value from the context. If no value is stored under the
|
||||||
// provided key, then this will return None.
|
// provided key, then this will return None.
|
||||||
pub fn value<V>(&self, key: &'static str) -> Option<&V>
|
pub fn value<V>(&self, key: String) -> Option<&V>
|
||||||
where
|
where
|
||||||
V: Any + Send + Sync + Sized,
|
V: Any + Send + Sync + Sized,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue