From e89ebb2c792fc9e2e034d0cddc38d1ed2d25c96d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 13 Jan 2022 06:58:08 +0000 Subject: [PATCH] Use Strings in context values map --- src/ctx/context.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ctx/context.rs b/src/ctx/context.rs index 8e14c200..d4d9d3a6 100644 --- a/src/ctx/context.rs +++ b/src/ctx/context.rs @@ -17,7 +17,13 @@ pub struct Context { // Wether or not this context is cancelled. cancelled: Arc, // A collection of read only values stored in this context. - values: Option>>, + values: Option>>, +} + +impl Default for Context { + fn default() -> Self { + Context::background() + } } impl Context { @@ -74,7 +80,7 @@ impl Context { // Add a value to the context. It overwrites any previously set values // with the same key. - pub fn add_value(&mut self, key: &'static str, value: V) + pub fn add_value(&mut self, key: String, value: V) where V: Any + Send + Sync + Sized, { @@ -148,7 +154,7 @@ impl Context { // Get a value from the context. If no value is stored under the // provided key, then this will return None. - pub fn value(&self, key: &'static str) -> Option<&V> + pub fn value(&self, key: String) -> Option<&V> where V: Any + Send + Sync + Sized, {