mirror of
https://github.com/sagiegurari/duckscript
synced 2024-07-20 17:55:45 +00:00
Add support for Any state value
This commit is contained in:
parent
a3d4b7c747
commit
5165a30c10
|
@ -2,6 +2,7 @@
|
|||
|
||||
### v0.2.1
|
||||
|
||||
* Runtime - Add support for **Any** state type.
|
||||
* SDK - Use fsio crate for file system apis.
|
||||
* Runtime - Use fsio crate for file system apis.
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@ mod runtime_test;
|
|||
|
||||
use crate::types::command::Commands;
|
||||
use crate::types::instruction::Instruction;
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// enum defining what values can be stored in the state map
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -36,6 +39,8 @@ pub enum StateValue {
|
|||
List(Vec<StateValue>),
|
||||
/// sub state value
|
||||
SubState(HashMap<String, StateValue>),
|
||||
/// any value
|
||||
Any(Rc<RefCell<dyn Any>>),
|
||||
}
|
||||
|
||||
/// The context structure
|
||||
|
|
|
@ -144,6 +144,7 @@ pub(crate) fn get_as_string(state_value: &StateValue) -> Result<String, String>
|
|||
StateValue::ByteArray(_) => Err("Unsupported value type.".to_string()),
|
||||
StateValue::List(_) => Err("Unsupported value type.".to_string()),
|
||||
StateValue::SubState(_) => Err("Unsupported value type.".to_string()),
|
||||
StateValue::Any(_) => Err("Unsupported value type.".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +205,10 @@ where
|
|||
state.insert(key, StateValue::List(value));
|
||||
Err("Invalid handle provided.".to_string())
|
||||
}
|
||||
StateValue::Any(value) => {
|
||||
state.insert(key, StateValue::Any(value));
|
||||
Err("Invalid handle provided.".to_string())
|
||||
}
|
||||
},
|
||||
None => Err(format!("Handle: {} not found.", &key).to_string()),
|
||||
}
|
||||
|
@ -266,6 +271,10 @@ where
|
|||
state.insert(key, StateValue::SubState(value));
|
||||
Err("Invalid handle provided.".to_string())
|
||||
}
|
||||
StateValue::Any(value) => {
|
||||
state.insert(key, StateValue::Any(value));
|
||||
Err("Invalid handle provided.".to_string())
|
||||
}
|
||||
},
|
||||
None => Err(format!("Handle: {} not found.", &key).to_string()),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue