changed Object API

This commit is contained in:
JOLIMAITRE Matthieu 2022-06-01 04:00:06 +03:00
parent dcf2bac9b6
commit fe99fddc29
2 changed files with 10 additions and 4 deletions

View file

@ -128,12 +128,12 @@ fn obj(_: Vec<Value>) -> Value {
Value::Object(HashMap::new())
}
fn set(mut args: Vec<Value>) -> Value {
fn set(args: Vec<Value>) -> Value {
let mut object = args.get(0).unwrap().as_object().unwrap().clone();
let name = args.get(1).unwrap().as_string().unwrap().to_string();
let value = args.get(2).unwrap().clone();
let object = args.get_mut(0).unwrap().as_object_mut().unwrap();
object.insert(name, value.clone());
value
object.insert(name, value);
object.into()
}
fn get(args: Vec<Value>) -> Value {

View file

@ -139,6 +139,12 @@ impl From<&str> for Value {
}
}
impl From<HashMap<String, Value>> for Value {
fn from(value: HashMap<String, Value>) -> Self {
Self::Object(value)
}
}
impl<T> From<Option<T>> for Value
where
T: Into<Value>,