y-rb 0.2.0-aarch64-linux → 0.3.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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: b4056a6e2632674613df152e809956da2f6a4656377258f4c9543785a9aa16fa
|
4
|
+
data.tar.gz: efbce452e05d767ab74d8ed1cc553767511cacd913e521e88104f26201c9040d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4454984ce16422d39adebd711504f37eb0e9470a89aac852bfbe82bff3d7fc1c3fbed112aca3b37ddc37aa437d8d17acdc41b64afb29c3af0e114fc14fabac08
|
7
|
+
data.tar.gz: 29b5f6e9db3015fe7d5892276d5baf3e75ea63168fe8f0f191360a43108406f4cf46b984faf38b21c136990620842ff36b455942a85431c343a5237cf61c4851
|
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
|
|