teo_runtime/model/object/
input.rs1use indexmap::IndexMap;
2use self::Input::{SetValue, AtomicUpdater};
3use crate::value::value::Value;
4
5
6pub enum Input {
7 SetValue(Value),
8 AtomicUpdater(Value),
9}
10
11impl Input {
12
13 pub fn decode_field(updator: &Value) -> Input {
14 if let Some(updator_map) = updator.as_dictionary() {
15 let key = updator_map.keys().next().unwrap();
16 let value = updator_map.values().next().unwrap();
17 if key.as_str() == "set" {
18 SetValue(value.clone())
19 } else {
20 AtomicUpdater(updator.clone())
21 }
22 } else {
23 SetValue(updator.clone())
24 }
25 }
26
27 pub fn key_value(value: &IndexMap<String, Value>) -> (&str, &Value) {
28 (value.keys().next().unwrap().as_str(), value.values().next().unwrap())
29 }
30
31 pub fn has_i_mode(map: &IndexMap<String, Value>) -> bool {
32 match map.get("mode") {
33 Some(val) => {
34 if let Some(variant) = val.as_str() {
35 return variant == "caseInsensitive"
36 } else {
37 false
38 }
39 }
40 None => {
41 false
42 }
43 }
44 }
45
46 pub fn has_negative_take(json_value: &Value) -> bool {
47 if json_value.is_dictionary() {
48 let take = json_value.as_dictionary().unwrap().get("take");
49 if take.is_some() {
50 let take = take.unwrap();
51 if take.is_any_int() {
52 let take = take.to_int64().unwrap();
53 return take < 0;
54 }
55 }
56 }
57 false
58 }
59}