Skip to content

Commit

Permalink
Make Value Sync + Send
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Jun 19, 2024
1 parent 670e4bd commit ea48158
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions interpreter/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt::{Display, Formatter};
use std::rc::Rc;
use std::sync::Arc;

#[derive(Debug, PartialEq, Clone)]
pub struct Map {
pub map: Rc<HashMap<Key, Value>>,
pub map: Arc<HashMap<Key, Value>>,
}

impl PartialOrd for Map {
Expand Down Expand Up @@ -126,7 +125,7 @@ impl<K: Into<Key>, V: Into<Value>> From<HashMap<K, V>> for Map {
new_map.insert(k.into(), v.into());
}
Map {
map: Rc::new(new_map),
map: Arc::new(new_map),
}
}
}
Expand Down Expand Up @@ -171,6 +170,9 @@ pub enum Value {
Null,
}

unsafe impl Sync for Value {}
unsafe impl Send for Value {}

pub enum ValueType {
List,
Map,
Expand Down Expand Up @@ -516,7 +518,10 @@ impl<'a> Value {
let value = Value::resolve(v, ctx)?;
map.insert(key, value);
}
Value::Map(Map { map: Rc::from(map) }).into()
Value::Map(Map {
map: Arc::from(map),
})
.into()
}
Expression::Ident(name) => {
if ctx.has_function(&***name) {
Expand Down Expand Up @@ -686,7 +691,7 @@ impl ops::Add<Value> for Value {
for (k, v) in r.map.iter() {
new.insert(k.clone(), v.clone());
}
Value::Map(Map { map: Rc::new(new) })
Value::Map(Map { map: Arc::new(new) })
}
(Value::Duration(l), Value::Duration(r)) => Value::Duration(l + r),
(Value::Timestamp(l), Value::Duration(r)) => Value::Timestamp(l + r),
Expand Down

0 comments on commit ea48158

Please sign in to comment.