No need to clone key when fetching value on context

This commit is contained in:
Tobie Morgan Hitchcock 2022-04-05 09:56:19 +01:00
parent aab4d0b096
commit c1a128e7ab
2 changed files with 3 additions and 3 deletions

View file

@ -146,12 +146,12 @@ 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: String) -> Option<&V> pub fn value<V>(&self, key: &str) -> Option<&V>
where where
V: Any + Send + Sync + Sized, V: Any + Send + Sync + Sized,
{ {
if let Some(ref values) = self.values { if let Some(ref values) = self.values {
if let Some(value) = values.get(&key) { if let Some(value) = values.get(key) {
let value: &dyn Any = &**value; let value: &dyn Any = &**value;
return value.downcast_ref::<V>(); return value.downcast_ref::<V>();
} }

View file

@ -37,7 +37,7 @@ impl Param {
// Find a base variable by name // Find a base variable by name
match self.name.parts.first() { match self.name.parts.first() {
// The first part will be a field // The first part will be a field
Some(Part::Field(v)) => match ctx.value::<Value>(v.name.clone()) { Some(Part::Field(v)) => match ctx.value::<Value>(&v.name) {
// The base variable exists // The base variable exists
Some(v) => { Some(v) => {
// Get the path parts // Get the path parts