1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! This library offers a boilerplate free approach to track struct data modifications.
//! For optimization, only the adjusted fields are tracked. Changes will be serialized and sent on an channel.
//!
//! ## Examples
//!
//! First, add `track` attribute to mark your struct as trackable.
//! ```rust
//! // imports all necessarily types for the `track` attribute.
//! use track::preclude::*;
//!
//! #[track]
//! #[derive(Debug)]
//! pub struct Position {
//! pub x: u32,
//! pub y: u32,
//! }
//! ```
//!
//! You can specify a serialization method for the track macro.
//! Give the name of the type that implements [SerializationStrategy](https://docs.rs/track/serialization/trait.SerializationStrategy.html), and make sure it is in scope for the macro.
//! Such as:
//!
//! ```rust
//! use track::serialization::bincode::Bincode;
//!
//! #[track(serialization = "Bincode")]
//! struct Postition ...
//! ```
//!
//! Now let us make some modifications and apply those to other instances.
//! ```rust
//! use track::{preclude::*, serialization::bincode::Bincode, Apply, ModificationChannel};
//!
//! #[derive(Copy, Clone, Debug, PartialEq)]
//! pub struct Identity {
//! pub value: u8,
//! }
//!
//! impl Identifier for Identity {}
//!
//! fn main() {
//! let channel = ModificationChannel::<Identity>::new();
//!
//! let updated_storage = vec![
//! (Identity { value: 1 }, Position { x: 0, y: 0 }),
//! (Identity { value: 2 }, Position { x: 0, y: 0 }),
//! ];
//! let mut outdated_storage = updated_storage.clone();
//!
//! // == Make changes to storage ==
//! make_changes(&channel, updated_storage);
//!
//! // == Apply changes to outdated storage ==
//! apply_changes(&channel, &mut outdated_storage);
//! }
//!
//! fn make_changes(channel: &ModificationChannel<Identity>, entities: Vec<(Identity, Position)>) {
//! for (id, mut position) in entities {
//! let mut position = position.track(channel.sender(), id); /* returns `Tracker` which tracks changes */
//!
//! // `Tracker` implements `DerefMut`
//! position.x += 1;
//! position.y += 1;
//! } // <- on the `Drop` of `wrapper` changes are serialized and sent on the channel.
//! }
//!
//! fn apply_changes(
//! channel: &ModificationChannel<Identity>,
//! entities: &mut Vec<(Identity, Position)>,
//! ) {
//! for event in channel.receiver().try_iter() {
//! let entity = entities
//! .iter_mut()
//! .find(|e| e.0 == event.identifier)
//! .unwrap();
//!
//! Apply::apply_to(&mut entity.1, &event.modified_fields, Bincode);
//!
//! println!("entity updated {:?}", entity);
//! }
//! }
//! ```
//!
//! _For a more in-depth example checkout the [examples](https://github.com/entity-sync-rs/track/tree/master/examples) on github._
use Sender;
use SerdeDiff;
pub use ;
pub use track;
use Debug;
/// A trait with functions for tracking struct value modifications.
///
/// Do not implement this trait manually but use the `track` attribute for less boiler plate code.
/// A marker trait with a number of requirements that are mandatory for trackable types.
/// A marker trait witch should be implemented for types used as identity in the [Tracker](./struct.Tracker.html).
/// A re-export with types needed for the [track](./struct.Tracker.html) attribute.