Skip to content

Commit 0f35f4f

Browse files
committed
Make reborrow fixes easier to read
1 parent 36912b0 commit 0f35f4f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

objc2-foundation/src/array.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,16 @@ impl<T: Message, O: Ownership> NSMutableArray<T, O> {
272272
obj
273273
}
274274

275+
fn remove_last(&mut self) {
276+
unsafe { msg_send![self, removeLastObject] }
277+
}
278+
275279
#[doc(alias = "removeLastObject")]
276280
pub fn pop(&mut self) -> Option<Id<T, O>> {
277281
self.last()
278282
.map(|obj| unsafe { Id::retain(obj as *const T as *mut T).unwrap_unchecked() })
279283
.map(|obj| {
280-
unsafe {
281-
let _: () = msg_send![self, removeLastObject];
282-
}
284+
self.remove_last();
283285
obj
284286
})
285287
}

objc2-foundation/src/data.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ impl NSMutableData {
154154

155155
/// Mutation methods
156156
impl NSMutableData {
157+
// Helps with reborrowing issue
158+
fn raw_bytes_mut(&mut self) -> *mut c_void {
159+
unsafe { msg_send![self, mutableBytes] }
160+
}
161+
157162
#[doc(alias = "mutableBytes")]
158163
pub fn bytes_mut(&mut self) -> &mut [u8] {
159-
let this = &mut *self; // Reborrow
160-
let ptr: *mut c_void = unsafe { msg_send![this, mutableBytes] };
164+
let ptr = self.raw_bytes_mut();
161165
// The bytes pointer may be null for length zero
162166
if ptr.is_null() {
163167
&mut []

0 commit comments

Comments
 (0)