datex_core/values/value/
update_handler.rs1use crate::{
2 prelude::*,
3 shared_values::base_shared_value_container::observers::TransceiverId,
4 value_updates::{
5 errors::UpdateError,
6 update_data::{
7 AppendEntryUpdateData, DeleteEntryUpdateData, ListSpliceUpdateData,
8 SetEntryUpdateData,
9 },
10 update_handler::UpdateHandler,
11 },
12 values::{
13 core_value::CoreValue, value::Value, value_container::ValueContainer,
14 },
15};
16
17impl UpdateHandler for Value {
18 fn try_set_entry(
19 &mut self,
20 data: SetEntryUpdateData,
21 source_id: TransceiverId,
22 ) -> Result<(), UpdateError> {
23 match self.inner {
24 CoreValue::Map(ref mut map) => map.try_set_entry(data, source_id),
25 CoreValue::List(ref mut list) => {
26 list.try_set_entry(data, source_id)
27 }
28 _ => Err(UpdateError::InvalidUpdate),
29 }
30 }
31
32 fn try_delete_entry(
33 &mut self,
34 data: DeleteEntryUpdateData,
35 source_id: TransceiverId,
36 ) -> Result<ValueContainer, UpdateError> {
37 match self.inner {
38 CoreValue::Map(ref mut map) => {
39 map.try_delete_entry(data, source_id)
40 }
41 CoreValue::List(ref mut list) => {
42 list.try_delete_entry(data, source_id)
43 }
44 _ => Err(UpdateError::InvalidUpdate),
45 }
46 }
47
48 fn try_append_entry(
49 &mut self,
50 data: AppendEntryUpdateData,
51 source_id: TransceiverId,
52 ) -> Result<(), UpdateError> {
53 match self.inner {
54 CoreValue::Map(ref mut map) => {
55 map.try_append_entry(data, source_id)
56 }
57 CoreValue::List(ref mut list) => {
58 list.try_append_entry(data, source_id)
59 }
60 _ => Err(UpdateError::InvalidUpdate),
61 }
62 }
63
64 fn try_clear(
65 &mut self,
66 source_id: TransceiverId,
67 ) -> Result<(), UpdateError> {
68 match self.inner {
69 CoreValue::Map(ref mut map) => map.try_clear(source_id),
70 CoreValue::List(ref mut list) => list.try_clear(source_id),
71 _ => Err(UpdateError::InvalidUpdate),
72 }
73 }
74
75 fn try_list_splice(
76 &mut self,
77 _data: ListSpliceUpdateData,
78 _source_id: TransceiverId,
79 ) -> Result<Vec<ValueContainer>, UpdateError> {
80 match self.inner {
81 CoreValue::List(ref mut list) => {
82 list.try_list_splice(_data, _source_id)
83 }
84 _ => Err(UpdateError::InvalidUpdate),
85 }
86 }
87}