y-rb 0.1.7-x86_64-linux-musl → 0.3.0-x86_64-linux-musl

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.
@@ -15,7 +15,7 @@ pub(crate) struct YArray(pub(crate) RefCell<Array>);
15
15
  unsafe impl Send for YArray {}
16
16
 
17
17
  impl YArray {
18
- pub(crate) fn yarray_each(&self, block: Proc) -> () {
18
+ pub(crate) fn yarray_each(&self, block: Proc) {
19
19
  self.0.borrow_mut().iter().for_each(|val| {
20
20
  let yvalue = YValue::from(val);
21
21
  let args = (yvalue.into(),);
@@ -26,37 +26,28 @@ impl YArray {
26
26
  let v = self.0.borrow().get(index).unwrap();
27
27
  YValue::from(v).into()
28
28
  }
29
- pub(crate) fn yarray_insert(
30
- &self,
31
- transaction: &YTransaction,
32
- index: u32,
33
- value: Value
34
- ) -> () {
29
+ pub(crate) fn yarray_insert(&self, transaction: &YTransaction, index: u32, value: Value) {
35
30
  let yvalue = YValue::from(value);
36
31
  let avalue = Any::from(yvalue);
37
- self.0.borrow_mut().insert(
38
- &mut *transaction.0.borrow_mut(),
39
- index,
40
- avalue
41
- );
32
+ self.0
33
+ .borrow_mut()
34
+ .insert(&mut *transaction.0.borrow_mut(), index, avalue);
42
35
  }
43
36
  pub(crate) fn yarray_insert_range(
44
37
  &self,
45
38
  transaction: &YTransaction,
46
39
  index: u32,
47
- values: RArray
48
- ) -> () {
40
+ values: RArray,
41
+ ) {
49
42
  let arr: Vec<Any> = values
50
43
  .each()
51
44
  .into_iter()
52
45
  .map(|value| YValue::from(value.unwrap()).into())
53
46
  .collect();
54
47
 
55
- self.0.borrow_mut().insert_range(
56
- &mut *transaction.0.borrow_mut(),
57
- index,
58
- arr
59
- );
48
+ self.0
49
+ .borrow_mut()
50
+ .insert_range(&mut *transaction.0.borrow_mut(), index, arr);
60
51
  }
61
52
  pub(crate) fn yarray_length(&self) -> u32 {
62
53
  return self.0.borrow().len();
@@ -82,30 +73,28 @@ impl YArray {
82
73
  Change::Added(v) => {
83
74
  let values = v
84
75
  .iter()
85
- .map(|v| {
86
- <YValue as Into<Value>>::into(
87
- YValue::from(v.clone())
88
- )
89
- })
76
+ .map(|v| <YValue as Into<Value>>::into(YValue::from(v.clone())))
90
77
  .collect::<RArray>();
91
78
  payload.aset(change_added, values)
92
79
  }
93
- Change::Retain(position) => payload
94
- .aset(change_retain, Value::from(*position)),
95
- Change::Removed(position) => payload
96
- .aset(change_removed, Value::from(*position))
80
+ Change::Retain(position) => {
81
+ payload.aset(change_retain, Value::from(*position))
82
+ }
83
+ Change::Removed(position) => {
84
+ payload.aset(change_removed, Value::from(*position))
85
+ }
97
86
  };
98
87
 
99
88
  match result {
100
89
  Ok(()) => Ok(payload),
101
- Err(e) => Err(e)
90
+ Err(e) => Err(e),
102
91
  }
103
92
  })
104
93
  .partition(Result::is_ok);
105
94
 
106
- if errors.len() == 0 {
95
+ if errors.is_empty() {
107
96
  let args = (RArray::from_vec(
108
- changes.into_iter().map(Result::unwrap).collect()
97
+ changes.into_iter().map(Result::unwrap).collect(),
109
98
  ),);
110
99
  let _ = block.call::<(RArray,), Qnil>(args);
111
100
  // todo: make sure we respect the result and bubble up the
@@ -119,48 +108,29 @@ impl YArray {
119
108
 
120
109
  Ok(subscription_id)
121
110
  }
122
- pub(crate) fn yarray_push_back(
123
- &self,
124
- transaction: &YTransaction,
125
- value: Value
126
- ) -> () {
111
+ pub(crate) fn yarray_push_back(&self, transaction: &YTransaction, value: Value) {
127
112
  let yvalue = YValue::from(value);
128
113
  let avalue = Any::from(yvalue);
129
114
  self.0
130
115
  .borrow_mut()
131
116
  .push_back(&mut *transaction.0.borrow_mut(), avalue)
132
117
  }
133
- pub(crate) fn yarray_push_front(
134
- &self,
135
- transaction: &YTransaction,
136
- value: Value
137
- ) -> () {
118
+ pub(crate) fn yarray_push_front(&self, transaction: &YTransaction, value: Value) {
138
119
  let yvalue = YValue::from(value);
139
120
  let avalue = Any::from(yvalue);
140
121
  self.0
141
122
  .borrow_mut()
142
123
  .push_front(&mut *transaction.0.borrow_mut(), avalue)
143
124
  }
144
- pub(crate) fn yarray_remove(
145
- &self,
146
- transaction: &YTransaction,
147
- index: u32
148
- ) -> () {
125
+ pub(crate) fn yarray_remove(&self, transaction: &YTransaction, index: u32) {
149
126
  self.0
150
127
  .borrow_mut()
151
128
  .remove(&mut transaction.0.borrow_mut(), index)
152
129
  }
153
- pub(crate) fn yarray_remove_range(
154
- &self,
155
- transaction: &YTransaction,
156
- index: u32,
157
- len: u32
158
- ) -> () {
159
- self.0.borrow_mut().remove_range(
160
- &mut transaction.0.borrow_mut(),
161
- index,
162
- len
163
- )
130
+ pub(crate) fn yarray_remove_range(&self, transaction: &YTransaction, index: u32, len: u32) {
131
+ self.0
132
+ .borrow_mut()
133
+ .remove_range(&mut transaction.0.borrow_mut(), index, len)
164
134
  }
165
135
  pub(crate) fn yarray_to_a(&self) -> RArray {
166
136
  let arr = self
@@ -170,9 +140,9 @@ impl YArray {
170
140
  .map(|v| YValue::from(v).into())
171
141
  .collect::<Vec<Value>>();
172
142
 
173
- return RArray::from_vec(arr);
143
+ RArray::from_vec(arr)
174
144
  }
175
- pub(crate) fn yarray_unobserve(&self, subscription_id: u32) -> () {
145
+ pub(crate) fn yarray_unobserve(&self, subscription_id: u32) {
176
146
  self.0.borrow_mut().unobserve(subscription_id);
177
147
  }
178
148
  }
@@ -10,7 +10,7 @@ pub(crate) struct YAttrs(pub(crate) Attrs);
10
10
 
11
11
  impl From<Attrs> for YAttrs {
12
12
  fn from(value: Attrs) -> Self {
13
- YAttrs { 0: value }
13
+ YAttrs(value)
14
14
  }
15
15
  }
16
16
 
@@ -29,7 +29,7 @@ impl From<RHash> for YAttrs {
29
29
  })
30
30
  .expect("cannot iterate attributes hash");
31
31
 
32
- YAttrs { 0: attrs }
32
+ YAttrs(attrs)
33
33
  }
34
34
  }
35
35
 
@@ -0,0 +1,155 @@
1
+ use crate::awareness::{Awareness, AwarenessUpdate, Event};
2
+ use magnus::block::Proc;
3
+ use magnus::{Error, Value};
4
+ use std::borrow::Borrow;
5
+ use std::cell::RefCell;
6
+ use std::collections::HashMap;
7
+ use yrs::block::ClientID;
8
+ use yrs::updates::decoder::Decode;
9
+ use yrs::updates::encoder::Encode;
10
+ use yrs::Doc;
11
+
12
+ #[magnus::wrap(class = "Y::Awareness")]
13
+ pub(crate) struct YAwareness(pub(crate) RefCell<Awareness>);
14
+
15
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
16
+ unsafe impl Send for YAwareness {}
17
+
18
+ impl YAwareness {
19
+ pub(crate) fn yawareness_new() -> Self {
20
+ let doc = Doc::new();
21
+ let awareness = Awareness::new(doc);
22
+
23
+ Self(RefCell::new(awareness))
24
+ }
25
+
26
+ pub(crate) fn yawareness_apply_update(&self, update: &YAwarenessUpdate) -> Result<(), Error> {
27
+ update.decode().and_then(|value| {
28
+ self.0
29
+ .borrow_mut()
30
+ .apply_update(value)
31
+ .map_err(|_error| Error::runtime_error("cannot decode awareness update"))
32
+ })
33
+ }
34
+
35
+ pub(crate) fn yawareness_clean_local_state(&self) {
36
+ self.0.borrow_mut().clean_local_state();
37
+ }
38
+
39
+ pub(crate) fn yawareness_client_id(&self) -> ClientID {
40
+ self.0.borrow().client_id()
41
+ }
42
+
43
+ pub(crate) fn yawareness_clients(&self) -> HashMap<ClientID, String> {
44
+ self.0.borrow().clients().to_owned()
45
+ }
46
+
47
+ pub(crate) fn yawareness_local_state(&self) -> Option<String> {
48
+ self.0.borrow().local_state().map(|value| value.to_string())
49
+ }
50
+
51
+ pub(crate) fn yawareness_on_update(&self, block: Proc) -> Result<u32, Error> {
52
+ let subscription_id = self
53
+ .0
54
+ .borrow_mut()
55
+ .on_update(move |_awareness, event| {
56
+ let awareness_event = YAwarenessEvent::from(event);
57
+ let args = (awareness_event,);
58
+ block
59
+ .call::<(YAwarenessEvent,), Value>(args)
60
+ .expect("cannot call block: on_update");
61
+ })
62
+ .into();
63
+
64
+ Ok(subscription_id)
65
+ }
66
+
67
+ pub(crate) fn yawareness_remove_on_update(&self, subscription_id: u32) {
68
+ self.0.borrow_mut().remove_on_update(subscription_id)
69
+ }
70
+
71
+ pub(crate) fn yawareness_remove_state(&self, client_id: ClientID) {
72
+ self.0.borrow_mut().remove_state(client_id)
73
+ }
74
+
75
+ pub(crate) fn yawareness_set_local_state(&self, json: String) {
76
+ self.0.borrow_mut().set_local_state(json)
77
+ }
78
+
79
+ pub(crate) fn yawareness_update(&self) -> Result<YAwarenessUpdate, Error> {
80
+ self.0
81
+ .borrow_mut()
82
+ .update()
83
+ .map(YAwarenessUpdate::from)
84
+ .map_err(|_error| Error::runtime_error("cannot update awareness"))
85
+ }
86
+
87
+ pub(crate) fn yawareness_update_with_clients(
88
+ &self,
89
+ clients: Vec<ClientID>,
90
+ ) -> Result<YAwarenessUpdate, Error> {
91
+ self.0
92
+ .borrow_mut()
93
+ .update_with_clients(clients)
94
+ .map(YAwarenessUpdate::from)
95
+ .map_err(|_error| Error::runtime_error("cannot update awareness with clients"))
96
+ }
97
+ }
98
+
99
+ impl From<Awareness> for YAwareness {
100
+ fn from(value: Awareness) -> Self {
101
+ Self(RefCell::from(value))
102
+ }
103
+ }
104
+
105
+ #[magnus::wrap(class = "Y::AwarenessUpdate")]
106
+ pub(crate) struct YAwarenessUpdate(pub(crate) Vec<u8>);
107
+
108
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
109
+ unsafe impl Send for YAwarenessUpdate {}
110
+
111
+ impl YAwarenessUpdate {
112
+ pub(crate) fn decode(&self) -> Result<AwarenessUpdate, Error> {
113
+ AwarenessUpdate::decode_v1(self.0.borrow())
114
+ .map_err(|_error| Error::runtime_error("cannot decode awareness update"))
115
+ }
116
+ pub(crate) fn yawareness_update_encode(&self) -> Vec<u8> {
117
+ self.0.to_vec()
118
+ }
119
+ }
120
+
121
+ impl From<AwarenessUpdate> for YAwarenessUpdate {
122
+ fn from(value: AwarenessUpdate) -> Self {
123
+ YAwarenessUpdate(value.encode_v1())
124
+ }
125
+ }
126
+
127
+ impl From<Vec<u8>> for YAwarenessUpdate {
128
+ fn from(value: Vec<u8>) -> Self {
129
+ YAwarenessUpdate(value)
130
+ }
131
+ }
132
+
133
+ #[magnus::wrap(class = "Y::AwarenessEvent")]
134
+ pub(crate) struct YAwarenessEvent(Event);
135
+
136
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
137
+ unsafe impl Send for YAwarenessEvent {}
138
+
139
+ impl YAwarenessEvent {
140
+ pub(crate) fn added(&self) -> Vec<ClientID> {
141
+ self.0.borrow().added().to_vec()
142
+ }
143
+ pub(crate) fn updated(&self) -> Vec<ClientID> {
144
+ self.0.borrow().updated().to_vec()
145
+ }
146
+ pub(crate) fn removed(&self) -> Vec<ClientID> {
147
+ self.0.borrow().removed().to_vec()
148
+ }
149
+ }
150
+
151
+ impl From<&Event> for YAwarenessEvent {
152
+ fn from(value: &Event) -> Self {
153
+ Self(value.clone())
154
+ }
155
+ }
data/ext/yrb/src/ydoc.rs CHANGED
@@ -13,8 +13,7 @@ impl YDoc {
13
13
 
14
14
  if client_id.len() == 1 {
15
15
  let value = client_id.first().unwrap();
16
- options.client_id =
17
- Integer::from_value(*value).unwrap().to_u64().unwrap();
16
+ options.client_id = Integer::from_value(*value).unwrap().to_u64().unwrap();
18
17
  }
19
18
 
20
19
  options.offset_kind = OffsetKind::Utf32;
@@ -26,14 +25,11 @@ impl YDoc {
26
25
  pub(crate) fn ydoc_transact(&self) -> YTransaction {
27
26
  let transaction = self.0.borrow().transact();
28
27
 
29
- return YTransaction(RefCell::new(transaction));
28
+ YTransaction(RefCell::new(transaction))
30
29
  }
31
- pub(crate) fn ydoc_encode_diff_v1(
32
- &self,
33
- state_vector: Vec<u8>,
34
- ) -> Result<Vec<u8>, Error> {
35
- return StateVector::decode_v1(&*state_vector)
30
+ pub(crate) fn ydoc_encode_diff_v1(&self, state_vector: Vec<u8>) -> Result<Vec<u8>, Error> {
31
+ StateVector::decode_v1(&*state_vector)
36
32
  .map(|sv| self.0.borrow().encode_state_as_update_v1(&sv))
37
- .map_err(|_e| Error::runtime_error("cannot encode diff"));
33
+ .map_err(|_e| Error::runtime_error("cannot encode diff"))
38
34
  }
39
35
  }
data/ext/yrb/src/ymap.rs CHANGED
@@ -21,7 +21,7 @@ impl YMap {
21
21
  pub(crate) fn ymap_contains(&self, key: Value) -> bool {
22
22
  match indifferent_hash_key(key) {
23
23
  None => false,
24
- Some(k) => self.0.borrow().contains(&*k)
24
+ Some(k) => self.0.borrow().contains(&*k),
25
25
  }
26
26
  }
27
27
  pub(crate) fn ymap_each(&self, proc: Proc) {
@@ -42,19 +42,17 @@ impl YMap {
42
42
  &self,
43
43
  transaction: &YTransaction,
44
44
  key: Value,
45
- value: Value
45
+ value: Value,
46
46
  ) -> Result<(), Error> {
47
47
  match indifferent_hash_key(key) {
48
48
  None => Err(Error::runtime_error(
49
- "invalid key type, make sure it is either a Symbol or a String"
49
+ "invalid key type, make sure it is either a Symbol or a String",
50
50
  )),
51
51
  Some(k) => {
52
52
  let v = Any::from(YValue::from(value));
53
- self.0.borrow_mut().insert(
54
- &mut *transaction.0.borrow_mut(),
55
- k,
56
- v
57
- );
53
+ self.0
54
+ .borrow_mut()
55
+ .insert(&mut *transaction.0.borrow_mut(), k, v);
58
56
 
59
57
  Ok(())
60
58
  }
@@ -75,20 +73,15 @@ impl YMap {
75
73
  match change {
76
74
  EntryChange::Inserted(v) => {
77
75
  let h = RHash::new();
78
- h.aset(
79
- Symbol::new(&key.to_string()),
80
- *YValue::from(v.clone()).0.borrow()
81
- )
82
- .expect("cannot add change::inserted");
76
+ h.aset(Symbol::new(key), *YValue::from(v.clone()).0.borrow())
77
+ .expect("cannot add change::inserted");
83
78
 
84
79
  let payload = RHash::new();
85
80
  payload
86
81
  .aset(change_inserted, h)
87
82
  .expect("cannot add change::inserted");
88
83
 
89
- changes
90
- .push(payload)
91
- .expect("cannot push changes::payload");
84
+ changes.push(payload).expect("cannot push changes::payload");
92
85
  }
93
86
  EntryChange::Updated(old, new) => {
94
87
  let values = RArray::with_capacity(2);
@@ -100,7 +93,7 @@ impl YMap {
100
93
  .expect("cannot push change::updated");
101
94
 
102
95
  let h = RHash::new();
103
- h.aset(Symbol::new(&key.to_string()), values)
96
+ h.aset(Symbol::new(key), values)
104
97
  .expect("cannot push change::updated");
105
98
 
106
99
  let payload = RHash::new();
@@ -108,26 +101,19 @@ impl YMap {
108
101
  .aset(change_updated, h)
109
102
  .expect("cannot push change::updated");
110
103
 
111
- changes
112
- .push(payload)
113
- .expect("cannot push changes::payload");
104
+ changes.push(payload).expect("cannot push changes::payload");
114
105
  }
115
106
  EntryChange::Removed(v) => {
116
107
  let h = RHash::new();
117
- h.aset(
118
- Symbol::new(&key.to_string()),
119
- *YValue::from(v.clone()).0.borrow()
120
- )
121
- .expect("cannot push change::removed");
108
+ h.aset(Symbol::new(key), *YValue::from(v.clone()).0.borrow())
109
+ .expect("cannot push change::removed");
122
110
 
123
111
  let payload = RHash::new();
124
112
  payload
125
113
  .aset(change_removed, h)
126
114
  .expect("cannot push change::removed");
127
115
 
128
- changes
129
- .push(payload)
130
- .expect("cannot push changes::payload");
116
+ changes.push(payload).expect("cannot push changes::payload");
131
117
  }
132
118
  }
133
119
  }
@@ -138,11 +124,7 @@ impl YMap {
138
124
  })
139
125
  .into()
140
126
  }
141
- pub(crate) fn ymap_remove(
142
- &self,
143
- transaction: &YTransaction,
144
- key: Value
145
- ) -> Option<Value> {
127
+ pub(crate) fn ymap_remove(&self, transaction: &YTransaction, key: Value) -> Option<Value> {
146
128
  indifferent_hash_key(key)
147
129
  .map(|k| {
148
130
  self.0
@@ -157,9 +139,10 @@ impl YMap {
157
139
  }
158
140
  pub(crate) fn ymap_to_h(&self) -> RHash {
159
141
  RHash::from_iter(
160
- self.0.borrow().iter().map(move |(k, v)| {
161
- (k.to_string(), *YValue::from(v).0.borrow())
162
- })
142
+ self.0
143
+ .borrow()
144
+ .iter()
145
+ .map(move |(k, v)| (k.to_string(), *YValue::from(v).0.borrow())),
163
146
  )
164
147
  }
165
148
  pub(crate) fn ymap_unobserve(&self, subscription_id: u32) {
data/ext/yrb/src/ytext.rs CHANGED
@@ -21,15 +21,12 @@ impl YText {
21
21
  transaction: &YTransaction,
22
22
  index: u32,
23
23
  length: u32,
24
- attrs: RHash
24
+ attrs: RHash,
25
25
  ) -> Result<(), Error> {
26
26
  let a = YAttrs::from(attrs);
27
- self.0.borrow_mut().format(
28
- &mut *transaction.0.borrow_mut(),
29
- index,
30
- length,
31
- a.0
32
- );
27
+ self.0
28
+ .borrow_mut()
29
+ .format(&mut *transaction.0.borrow_mut(), index, length, a.0);
33
30
 
34
31
  Ok(())
35
32
  }
@@ -37,13 +34,11 @@ impl YText {
37
34
  &self,
38
35
  transaction: &YTransaction,
39
36
  index: u32,
40
- chunk: String
37
+ chunk: String,
41
38
  ) -> Result<(), Error> {
42
- self.0.borrow_mut().insert(
43
- &mut *transaction.0.borrow_mut(),
44
- index,
45
- &*chunk
46
- );
39
+ self.0
40
+ .borrow_mut()
41
+ .insert(&mut *transaction.0.borrow_mut(), index, &*chunk);
47
42
 
48
43
  Ok(())
49
44
  }
@@ -51,16 +46,14 @@ impl YText {
51
46
  &self,
52
47
  transaction: &YTransaction,
53
48
  index: u32,
54
- content: Value
49
+ content: Value,
55
50
  ) -> Result<(), Error> {
56
51
  let yvalue = YValue::from(content);
57
52
  let avalue = Any::from(yvalue);
58
53
 
59
- self.0.borrow_mut().insert_embed(
60
- &mut *transaction.0.borrow_mut(),
61
- index,
62
- avalue
63
- );
54
+ self.0
55
+ .borrow_mut()
56
+ .insert_embed(&mut *transaction.0.borrow_mut(), index, avalue);
64
57
 
65
58
  Ok(())
66
59
  }
@@ -69,7 +62,7 @@ impl YText {
69
62
  transaction: &YTransaction,
70
63
  index: u32,
71
64
  embed: Value,
72
- attrs: RHash
65
+ attrs: RHash,
73
66
  ) -> Result<(), Error> {
74
67
  let yvalue = YValue::from(embed);
75
68
  let avalue = Any::from(yvalue);
@@ -80,7 +73,7 @@ impl YText {
80
73
  &mut *transaction.0.borrow_mut(),
81
74
  index,
82
75
  avalue,
83
- a.0
76
+ a.0,
84
77
  );
85
78
 
86
79
  Ok(())
@@ -90,7 +83,7 @@ impl YText {
90
83
  transaction: &YTransaction,
91
84
  index: u32,
92
85
  chunk: String,
93
- attrs: RHash
86
+ attrs: RHash,
94
87
  ) -> Result<(), Error> {
95
88
  let a = YAttrs::from(attrs);
96
89
 
@@ -98,7 +91,7 @@ impl YText {
98
91
  &mut *transaction.0.borrow_mut(),
99
92
  index,
100
93
  &*chunk,
101
- a.0
94
+ a.0,
102
95
  );
103
96
 
104
97
  Ok(())
@@ -133,27 +126,19 @@ impl YText {
133
126
  .into_iter()
134
127
  .map(|(key, val)| {
135
128
  let yvalue = YValue::from(val);
136
- (
137
- key.to_string(),
138
- yvalue.0.into_inner()
139
- )
129
+ (key.to_string(), yvalue.0.into_inner())
140
130
  })
141
131
  .collect::<RHash>()
142
132
  .into(),
143
- None => None
144
- })
145
- .map(|attrs_hash| {
146
- attrs_hash
147
- .map(|v| payload.aset(attributes, v))
148
- })
149
- .map(|_| {
150
- block.call::<(RHash,), Qnil>((payload,))
133
+ None => None,
151
134
  })
135
+ .map(|attrs_hash| attrs_hash.map(|v| payload.aset(attributes, v)))
136
+ .map(|_| block.call::<(RHash,), Qnil>((payload,)))
152
137
  }
153
138
  Delta::Retain(index, attrs) => {
154
139
  let payload = RHash::new();
155
140
 
156
- let yvalue = YValue::from(index.clone());
141
+ let yvalue = YValue::from(*index);
157
142
 
158
143
  payload
159
144
  .aset(delta_retain, yvalue.0.into_inner())
@@ -163,38 +148,28 @@ impl YText {
163
148
  .into_iter()
164
149
  .map(|(key, val)| {
165
150
  let yvalue = YValue::from(val);
166
- (
167
- key.to_string(),
168
- yvalue.0.into_inner()
169
- )
151
+ (key.to_string(), yvalue.0.into_inner())
170
152
  })
171
153
  .collect::<RHash>()
172
154
  .into(),
173
- None => None
174
- })
175
- .map(|attrs_hash| {
176
- attrs_hash
177
- .map(|v| payload.aset(attributes, v))
178
- })
179
- .map(|_| {
180
- block.call::<(RHash,), Qnil>((payload,))
155
+ None => None,
181
156
  })
157
+ .map(|attrs_hash| attrs_hash.map(|v| payload.aset(attributes, v)))
158
+ .map(|_| block.call::<(RHash,), Qnil>((payload,)))
182
159
  }
183
160
  Delta::Deleted(index) => {
184
161
  let payload = RHash::new();
185
162
 
186
- let yvalue = YValue::from(index.clone());
163
+ let yvalue = YValue::from(*index);
187
164
 
188
165
  payload
189
166
  .aset(delta_delete, yvalue.0.into_inner())
190
- .map(|()| {
191
- block.call::<(RHash,), Qnil>((payload,))
192
- })
167
+ .map(|()| block.call::<(RHash,), Qnil>((payload,)))
193
168
  }
194
169
  })
195
170
  .partition(Result::is_ok);
196
171
 
197
- if errors.len() > 0 {
172
+ if !errors.is_empty() {
198
173
  // todo: make sure we respect errors and let the method fail by
199
174
  // by returning a Result containing an Error
200
175
  }
@@ -212,13 +187,11 @@ impl YText {
212
187
  &self,
213
188
  transaction: &YTransaction,
214
189
  start: u32,
215
- length: u32
190
+ length: u32,
216
191
  ) -> Result<(), Error> {
217
- self.0.borrow_mut().remove_range(
218
- &mut *transaction.0.borrow_mut(),
219
- start,
220
- length
221
- );
192
+ self.0
193
+ .borrow_mut()
194
+ .remove_range(&mut *transaction.0.borrow_mut(), start, length);
222
195
 
223
196
  Ok(())
224
197
  }