Skip to main content

datex_core/value_updates/update_data/
mod.rs

1mod serde_dif;
2
3use strum::AsRefStr;
4
5use crate::shared_values::base_shared_value_container::observers::TransceiverId;
6mod append_entry;
7mod delete_entry;
8mod list_splice;
9mod replace;
10mod set_entry;
11
12pub use append_entry::*;
13pub use delete_entry::*;
14pub use list_splice::*;
15pub use replace::*;
16pub use set_entry::*;
17
18#[derive(Clone, Debug, PartialEq, AsRefStr)]
19#[strum(serialize_all = "snake_case")]
20pub enum UpdateData {
21    /// Represents a replacement operation for a value.
22    Replace(ReplaceUpdateData),
23
24    /// Represents an update to a specific property of a value.
25    /// The `key` specifies which property to update, and `value` is the new value for that property.
26    SetEntry(SetEntryUpdateData),
27
28    /// Represents the removal of a specific property from a value.
29    DeleteEntry(DeleteEntryUpdateData),
30
31    /// Represents clearing all elements from a collection-type value (like an array or map).
32    Clear,
33
34    /// Represents adding a new element to a collection-type value (like an array or map).
35    AppendEntry(AppendEntryUpdateData),
36
37    /// Special update operation for list values that allows splicing
38    ListSplice(ListSpliceUpdateData),
39}
40
41impl UpdateData {
42    /// Creates a new [Update] struct with the given [TransceiverId] as source id.
43    pub fn with_source(self, source_id: TransceiverId) -> Update {
44        Update {
45            source_id,
46            data: self,
47        }
48    }
49}
50/// Represents an update to a value from a source [TransceiverId]
51#[derive(Clone, Debug, PartialEq)]
52pub struct Update {
53    pub source_id: TransceiverId,
54    pub data: UpdateData,
55}
56
57impl Update {
58    /// Creates a new [Update]
59    pub fn new(source_id: TransceiverId, data: UpdateData) -> Self {
60        Update { source_id, data }
61    }
62}