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 +4 -4
- data/ext/yrb/Cargo.toml +1 -1
- data/ext/yrb/src/awareness.rs +26 -41
- data/ext/yrb/src/lib.rs +87 -152
- data/ext/yrb/src/utils.rs +1 -3
- data/ext/yrb/src/yany.rs +1 -1
- data/ext/yrb/src/yarray.rs +24 -54
- data/ext/yrb/src/yawareness.rs +10 -18
- data/ext/yrb/src/ydoc.rs +2 -6
- data/ext/yrb/src/ymap.rs +18 -35
- data/ext/yrb/src/ytext.rs +29 -56
- data/ext/yrb/src/ytransaction.rs +2 -8
- data/ext/yrb/src/yvalue.rs +5 -11
- data/ext/yrb/src/yxml_element.rs +44 -65
- data/ext/yrb/src/yxml_text.rs +26 -47
- data/lib/2.7/yrb.so +0 -0
- data/lib/3.0/yrb.so +0 -0
- data/lib/3.1/yrb.so +0 -0
- data/lib/y/array.rb +2 -0
- data/lib/y/awareness.rb +7 -2
- data/lib/y/doc.rb +1 -1
- data/lib/y/map.rb +2 -0
- data/lib/y/text.rb +1 -1
- data/lib/y/version.rb +1 -1
- data/lib/y/xml.rb +5 -2
- data/lib/y-rb.rb +2 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e764ed148987200b5fbc12af9eaab5d190a92d84cc030598ea26bf27e00de6a
|
4
|
+
data.tar.gz: ae736fae3d90db89290fde484491ed72e214655cc62420cf4a72a056f715a508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c47ffa342eb4a60b90f3c1e3da79f69429f0373a3361aa2b6316118c9d4c7c9b75234a8941bbbe7d8b3a6bcebb92123836eabed7ef6978349768fd99b90a59d4
|
7
|
+
data.tar.gz: 570cb9f86a7d37c990a80ff89bfa97a03b2a96261088f6c729d451a2791f6ac1ef8f36f4a81e1040b35562f66bcf1dd352d0cb52bc82bc43a889bff18c7cf172
|
data/ext/yrb/Cargo.toml
CHANGED
data/ext/yrb/src/awareness.rs
CHANGED
@@ -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)
|
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 =
|
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)
|
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
|
|