y-rb 0.2.0-x86_64-linux → 0.3.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 418711843273d8a6a06f3be1d9fab885a96a7d7410917cf8a14debf77201ab77
4
- data.tar.gz: 1d80e2ac0f1a66ca2a4b78aa5d7f6f94bb0ec13663ad3be735a7e9d3b409e83e
3
+ metadata.gz: 3e764ed148987200b5fbc12af9eaab5d190a92d84cc030598ea26bf27e00de6a
4
+ data.tar.gz: ae736fae3d90db89290fde484491ed72e214655cc62420cf4a72a056f715a508
5
5
  SHA512:
6
- metadata.gz: c02fb5b869f4e7debe8be2a7f8905bc937429a96ce93dfff918dfd3fbfbbdc8d7d7e08bd0996a115bc141f246d4be1ff44dcb5ef57b53ed382297101a8e8a15f
7
- data.tar.gz: a9d54db7831d83b6b93e70111d1716ccb75337e16e7eadd105e930d7d90c8875b5e1f8619802cf48929f042cd461b6a7283e6733fdeba242bebe89b923541fa1
6
+ metadata.gz: c47ffa342eb4a60b90f3c1e3da79f69429f0373a3361aa2b6316118c9d4c7c9b75234a8941bbbe7d8b3a6bcebb92123836eabed7ef6978349768fd99b90a59d4
7
+ data.tar.gz: 570cb9f86a7d37c990a80ff89bfa97a03b2a96261088f6c729d451a2791f6ac1ef8f36f4a81e1040b35562f66bcf1dd352d0cb52bc82bc43a889bff18c7cf172
data/ext/yrb/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "yrb"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  authors = ["Hannes Moser <box@hannesmoser.at>", "Hannes Moser <hmoser@gitlab.com>"]
5
5
  edition = "2021"
6
6
  homepage = "https://github.com/y-crdt/yrb"
@@ -27,7 +27,7 @@ pub struct Awareness {
27
27
  doc: Doc,
28
28
  states: HashMap<ClientID, String>,
29
29
  meta: HashMap<ClientID, MetaClientState>,
30
- on_update: Option<EventHandler<Event>>
30
+ on_update: Option<EventHandler<Event>>,
31
31
  }
32
32
 
33
33
  unsafe impl Send for Awareness {}
@@ -42,14 +42,14 @@ impl Awareness {
42
42
  doc,
43
43
  on_update: None,
44
44
  states: HashMap::new(),
45
- meta: HashMap::new()
45
+ meta: HashMap::new(),
46
46
  }
47
47
  }
48
48
 
49
49
  /// Returns a channel receiver for an incoming awareness events. This channel can be cloned.
50
50
  pub fn on_update<F>(&mut self, f: F) -> Subscription<Event>
51
51
  where
52
- F: Fn(&Awareness, &Event) -> () + 'static
52
+ F: Fn(&Awareness, &Event) + 'static,
53
53
  {
54
54
  let eh = self.on_update.get_or_insert_with(EventHandler::default);
55
55
  eh.subscribe(f)
@@ -91,19 +91,13 @@ impl Awareness {
91
91
  Entry::Occupied(mut e) => {
92
92
  e.insert(new);
93
93
  if let Some(eh) = self.on_update.as_ref() {
94
- eh.trigger(
95
- self,
96
- &Event::new(vec![], vec![client_id], vec![])
97
- );
94
+ eh.trigger(self, &Event::new(vec![], vec![client_id], vec![]));
98
95
  }
99
96
  }
100
97
  Entry::Vacant(e) => {
101
98
  e.insert(new);
102
99
  if let Some(eh) = self.on_update.as_ref() {
103
- eh.trigger(
104
- self,
105
- &Event::new(vec![client_id], vec![], vec![])
106
- );
100
+ eh.trigger(self, &Event::new(vec![client_id], vec![], vec![]));
107
101
  }
108
102
  }
109
103
  }
@@ -117,11 +111,7 @@ impl Awareness {
117
111
  if prev_state.is_some() {
118
112
  eh.trigger(
119
113
  self,
120
- &Event::new(
121
- Vec::default(),
122
- Vec::default(),
123
- vec![client_id]
124
- )
114
+ &Event::new(Vec::default(), Vec::default(), vec![client_id]),
125
115
  );
126
116
  }
127
117
  }
@@ -159,7 +149,7 @@ impl Awareness {
159
149
  /// otherwise a [Error::ClientNotFound] error will be returned.
160
150
  pub fn update_with_clients<I: IntoIterator<Item = ClientID>>(
161
151
  &self,
162
- clients: I
152
+ clients: I,
163
153
  ) -> Result<AwarenessUpdate, Error> {
164
154
  let mut res = HashMap::new();
165
155
  for client_id in clients {
@@ -183,10 +173,7 @@ impl Awareness {
183
173
  ///
184
174
  /// If current instance has an observer channel (see: [Awareness::with_observer]), applied
185
175
  /// changes will also be emitted as events.
186
- pub fn apply_update(
187
- &mut self,
188
- update: AwarenessUpdate
189
- ) -> Result<(), Error> {
176
+ pub fn apply_update(&mut self, update: AwarenessUpdate) -> Result<(), Error> {
190
177
  let now = Instant::now();
191
178
 
192
179
  let mut added = Vec::new();
@@ -199,9 +186,8 @@ impl Awareness {
199
186
  match self.meta.entry(client_id) {
200
187
  Entry::Occupied(mut e) => {
201
188
  let prev = e.get();
202
- let is_removed = prev.clock == clock
203
- && is_null
204
- && self.states.contains_key(&client_id);
189
+ let is_removed =
190
+ prev.clock == clock && is_null && self.states.contains_key(&client_id);
205
191
  let is_new = prev.clock < clock;
206
192
  if is_new || is_removed {
207
193
  if is_null {
@@ -267,15 +253,16 @@ impl Default for Awareness {
267
253
  }
268
254
  }
269
255
 
256
+ #[allow(clippy::type_complexity)]
270
257
  struct EventHandler<T> {
271
258
  seq_nr: u32,
272
- subscribers: Rc<RefCell<HashMap<u32, Box<dyn Fn(&Awareness, &T) -> ()>>>>
259
+ subscribers: Rc<RefCell<HashMap<u32, Box<dyn Fn(&Awareness, &T)>>>>,
273
260
  }
274
261
 
275
262
  impl<T> EventHandler<T> {
276
263
  pub fn subscribe<F>(&mut self, f: F) -> Subscription<T>
277
264
  where
278
- F: Fn(&Awareness, &T) -> () + 'static
265
+ F: Fn(&Awareness, &T) + 'static,
279
266
  {
280
267
  let subscription_id = self.seq_nr;
281
268
  self.seq_nr += 1;
@@ -286,7 +273,7 @@ impl<T> EventHandler<T> {
286
273
  }
287
274
  Subscription {
288
275
  subscription_id,
289
- subscribers: Rc::downgrade(&self.subscribers)
276
+ subscribers: Rc::downgrade(&self.subscribers),
290
277
  }
291
278
  }
292
279
 
@@ -307,18 +294,20 @@ impl<T> Default for EventHandler<T> {
307
294
  fn default() -> Self {
308
295
  EventHandler {
309
296
  seq_nr: 0,
310
- subscribers: Rc::new(RefCell::new(HashMap::new()))
297
+ subscribers: Rc::new(RefCell::new(HashMap::new())),
311
298
  }
312
299
  }
313
300
  }
314
301
 
315
302
  /// Whenever a new callback is being registered, a [Subscription] is made. Whenever this
316
303
  /// subscription a registered callback is cancelled and will not be called any more.
304
+ #[allow(clippy::type_complexity)]
317
305
  pub struct Subscription<T> {
318
306
  subscription_id: u32,
319
- subscribers: Weak<RefCell<HashMap<u32, Box<dyn Fn(&Awareness, &T) -> ()>>>>
307
+ subscribers: Weak<RefCell<HashMap<u32, Box<dyn Fn(&Awareness, &T)>>>>,
320
308
  }
321
309
 
310
+ #[allow(clippy::from_over_into)]
322
311
  impl<T> Into<SubscriptionId> for Subscription<T> {
323
312
  fn into(self) -> SubscriptionId {
324
313
  let id = self.subscription_id;
@@ -339,7 +328,7 @@ impl<T> Drop for Subscription<T> {
339
328
  /// A structure that represents an encodable state of an [Awareness] struct.
340
329
  #[derive(Debug, Eq, PartialEq)]
341
330
  pub struct AwarenessUpdate {
342
- clients: HashMap<ClientID, AwarenessUpdateEntry>
331
+ clients: HashMap<ClientID, AwarenessUpdateEntry>,
343
332
  }
344
333
 
345
334
  impl Encode for AwarenessUpdate {
@@ -373,7 +362,7 @@ impl Decode for AwarenessUpdate {
373
362
  #[derive(Debug, Eq, PartialEq)]
374
363
  pub struct AwarenessUpdateEntry {
375
364
  clock: u32,
376
- json: String
365
+ json: String,
377
366
  }
378
367
 
379
368
  /// Errors generated by an [Awareness] struct methods.
@@ -381,20 +370,20 @@ pub struct AwarenessUpdateEntry {
381
370
  pub enum Error {
382
371
  /// Client ID was not found in [Awareness] metadata.
383
372
  #[error("client ID `{0}` not found")]
384
- ClientNotFound(ClientID)
373
+ ClientNotFound(ClientID),
385
374
  }
386
375
 
387
376
  #[derive(Debug, Clone, PartialEq, Eq)]
388
377
  struct MetaClientState {
389
378
  clock: u32,
390
- last_updated: Instant
379
+ last_updated: Instant,
391
380
  }
392
381
 
393
382
  impl MetaClientState {
394
383
  fn new(clock: u32, last_updated: Instant) -> Self {
395
384
  MetaClientState {
396
385
  clock,
397
- last_updated
386
+ last_updated,
398
387
  }
399
388
  }
400
389
  }
@@ -404,19 +393,15 @@ impl MetaClientState {
404
393
  pub struct Event {
405
394
  added: Vec<ClientID>,
406
395
  updated: Vec<ClientID>,
407
- removed: Vec<ClientID>
396
+ removed: Vec<ClientID>,
408
397
  }
409
398
 
410
399
  impl Event {
411
- pub fn new(
412
- added: Vec<ClientID>,
413
- updated: Vec<ClientID>,
414
- removed: Vec<ClientID>
415
- ) -> Self {
400
+ pub fn new(added: Vec<ClientID>, updated: Vec<ClientID>, removed: Vec<ClientID>) -> Self {
416
401
  Event {
417
402
  added,
418
403
  updated,
419
- removed
404
+ removed,
420
405
  }
421
406
  }
422
407