From 1ef91e3fa7a488e42b0cbe6d9b858c66521ca329 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Tue, 5 May 2020 06:13:55 +0000 Subject: [PATCH] Runtime - Support for hashset state value --- CHANGELOG.md | 3 ++- duckscript/src/types/runtime.rs | 4 +++- duckscript_sdk/src/utils/state.rs | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6965a5..2a1cf62 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ### v0.3.4 -* \[Breaking Change\] Runtime - REPL mode doesn't stop due to crashes from user commands #103 * New unset command. * New array_contains command. * New map_contains_value command. @@ -10,6 +9,8 @@ * New get_all_var_names command #100 * New get_by_name command. * New set_by_name command. +* Runtime - Support for hashset state value. +* \[Breaking Change\] Runtime - REPL mode doesn't stop due to crashes from user commands #103 ### v0.3.3 (2020-04-15) diff --git a/duckscript/src/types/runtime.rs b/duckscript/src/types/runtime.rs index b90d0f6..5efcac5 100644 --- a/duckscript/src/types/runtime.rs +++ b/duckscript/src/types/runtime.rs @@ -11,7 +11,7 @@ use crate::types::command::Commands; use crate::types::instruction::Instruction; use std::any::Any; use std::cell::RefCell; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::rc::Rc; /// enum defining what values can be stored in the state map @@ -37,6 +37,8 @@ pub enum StateValue { ByteArray(Vec), /// list List(Vec), + /// unique set of values + Set(HashSet), /// sub state value SubState(HashMap), /// any value diff --git a/duckscript_sdk/src/utils/state.rs b/duckscript_sdk/src/utils/state.rs index 5d5415c..e8ae172 100644 --- a/duckscript_sdk/src/utils/state.rs +++ b/duckscript_sdk/src/utils/state.rs @@ -160,6 +160,7 @@ pub(crate) fn get_as_string(state_value: &StateValue) -> Result StateValue::String(value) => Ok(value.to_string()), StateValue::ByteArray(_) => Err("Unsupported value type.".to_string()), StateValue::List(_) => Err("Unsupported value type.".to_string()), + StateValue::Set(_) => Err("Unsupported value type.".to_string()), StateValue::SubState(_) => Err("Unsupported value type.".to_string()), StateValue::Any(_) => Err("Unsupported value type.".to_string()), } @@ -222,6 +223,10 @@ where state.insert(key, StateValue::List(value)); Err("Invalid handle provided.".to_string()) } + StateValue::Set(value) => { + state.insert(key, StateValue::Set(value)); + Err("Invalid handle provided.".to_string()) + } StateValue::Any(value) => { state.insert(key, StateValue::Any(value)); Err("Invalid handle provided.".to_string()) @@ -284,6 +289,10 @@ where state.insert(key, StateValue::ByteArray(value)); Err("Invalid handle provided.".to_string()) } + StateValue::Set(value) => { + state.insert(key, StateValue::Set(value)); + Err("Invalid handle provided.".to_string()) + } StateValue::SubState(value) => { state.insert(key, StateValue::SubState(value)); Err("Invalid handle provided.".to_string())