Skip to content

Commit

Permalink
Remove unsafe code from KwargsValues
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Dec 16, 2024
1 parent 683f27a commit e95d9bd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions minijinja/src/value/argtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use crate::error::{Error, ErrorKind};
use crate::value::{
DynObject, ObjectRepr, Packed, SmallStr, StringType, Value, ValueKind, ValueMap, ValueRepr,
DynObject, ObjectExt, ObjectRepr, Packed, SmallStr, StringType, Value, ValueKind, ValueMap,
ValueRepr,
};
use crate::vm::State;

Expand Down Expand Up @@ -762,20 +763,17 @@ impl Deref for KwargsValues {
}
}

impl KwargsValues {
fn as_value_map<'a>(self: &'a Arc<Self>) -> &'a Arc<ValueMap> {
// SAFETY: this is safe because of repr(transparent)
unsafe { std::mem::transmute(self) }
}
}

impl Object for KwargsValues {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
self.as_value_map().get_value(key)
self.0.get(key).cloned()
}

fn enumerate(self: &Arc<Self>) -> Enumerator {
self.as_value_map().enumerate()
self.mapped_enumerator(|this| Box::new(this.0.keys().cloned()))
}

fn enumerator_len(self: &Arc<Self>) -> Option<usize> {
Some(self.0.len())
}
}

Expand Down

0 comments on commit e95d9bd

Please sign in to comment.