Skip to content

Commit f3b3749

Browse files
committed
Cargo fmt
1 parent 7c578be commit f3b3749

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

src/hole.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,19 @@ pub(crate) struct Cursor {
2121
impl Cursor {
2222
fn next(mut self) -> Option<Self> {
2323
unsafe {
24-
self.hole.as_mut().next.map(|nhole| {
25-
Cursor {
26-
prev: self.hole,
27-
hole: nhole,
28-
}
24+
self.hole.as_mut().next.map(|nhole| Cursor {
25+
prev: self.hole,
26+
hole: nhole,
2927
})
3028
}
3129
}
3230

3331
fn current(&self) -> &Hole {
34-
unsafe {
35-
self.hole.as_ref()
36-
}
32+
unsafe { self.hole.as_ref() }
3733
}
3834

3935
fn previous(&self) -> &Hole {
40-
unsafe {
41-
self.prev.as_ref()
42-
}
36+
unsafe { self.prev.as_ref() }
4337
}
4438

4539
// On success, it returns the new allocation, and the linked list has been updated
@@ -128,8 +122,8 @@ impl Cursor {
128122
Some(HoleInfo {
129123
addr: back_padding_start,
130124
size: unsafe { hole_end.offset_from(back_padding_start) }
131-
.try_into()
132-
.unwrap(),
125+
.try_into()
126+
.unwrap(),
133127
})
134128
} else {
135129
// No, it does not.
@@ -142,7 +136,9 @@ impl Cursor {
142136
////////////////////////////////////////////////////////////////////////////
143137
let Cursor { mut prev, mut hole } = self;
144138
// Remove the current location from the previous node
145-
unsafe { prev.as_mut().next = None; }
139+
unsafe {
140+
prev.as_mut().next = None;
141+
}
146142
// Take the next node out of our current node
147143
let maybe_next_addr: Option<NonNull<Hole>> = unsafe { hole.as_mut().next.take() };
148144

@@ -153,8 +149,10 @@ impl Cursor {
153149
(None, None) => {
154150
// No padding at all, how lucky! We still need to connect the PREVIOUS node
155151
// to the NEXT node, if there was one
156-
unsafe { prev.as_mut().next = maybe_next_addr; }
157-
},
152+
unsafe {
153+
prev.as_mut().next = maybe_next_addr;
154+
}
155+
}
158156
(None, Some(singlepad)) | (Some(singlepad), None) => unsafe {
159157
// We have front padding OR back padding, but not both.
160158
//
@@ -195,7 +193,7 @@ impl Cursor {
195193

196194
// Then connect the OLD previous to the NEW FRONT padding
197195
prev.as_mut().next = Some(NonNull::new_unchecked(frontpad_ptr));
198-
}
196+
},
199197
}
200198

201199
// Well that went swimmingly! Hand off the allocation, with surgery performed successfully!
@@ -324,10 +322,10 @@ impl HoleList {
324322
match cursor.split_current(aligned_layout) {
325323
Ok((ptr, _len)) => {
326324
return Ok((NonNull::new(ptr).ok_or(())?, aligned_layout));
327-
},
325+
}
328326
Err(curs) => {
329327
cursor = curs.next().ok_or(())?;
330-
},
328+
}
331329
}
332330
}
333331
}
@@ -358,10 +356,11 @@ impl HoleList {
358356
/// Returns information about the first hole for test purposes.
359357
#[cfg(test)]
360358
pub fn first_hole(&self) -> Option<(*const u8, usize)> {
361-
self.first
362-
.next
363-
.as_ref()
364-
.map(|hole| (hole.as_ptr() as *mut u8 as *const u8, unsafe { hole.as_ref().size }))
359+
self.first.next.as_ref().map(|hole| {
360+
(hole.as_ptr() as *mut u8 as *const u8, unsafe {
361+
hole.as_ref().size
362+
})
363+
})
365364
}
366365
}
367366

@@ -381,7 +380,7 @@ struct HoleInfo {
381380
unsafe fn make_hole(addr: *mut u8, size: usize) -> NonNull<Hole> {
382381
let hole_addr = addr.cast::<Hole>();
383382
debug_assert_eq!(addr as usize % align_of::<Hole>(), 0);
384-
hole_addr.write(Hole {size, next: None});
383+
hole_addr.write(Hole { size, next: None });
385384
NonNull::new_unchecked(hole_addr)
386385
}
387386

@@ -475,7 +474,6 @@ impl Cursor {
475474
hole = next;
476475
}
477476
}
478-
479477
}
480478
}
481479

@@ -508,7 +506,7 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
508506
// Yup! It lives at the front of the list. Hooray! Attempt to merge
509507
// it with just ONE next node, since it is at the front of the list
510508
(cursor, 1)
511-
},
509+
}
512510
Err(mut cursor) => {
513511
// Nope. It lives somewhere else. Advance the list until we find its home
514512
while let Err(()) = cursor.try_insert_after(hole) {
@@ -519,7 +517,7 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
519517
// the current node to the new node, then once more to combine the new node
520518
// with the node after that.
521519
(cursor, 2)
522-
},
520+
}
523521
};
524522

525523
// We now need to merge up to two times to combine the current node with the next
@@ -529,14 +527,14 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
529527

530528
#[cfg(test)]
531529
pub mod test {
530+
use crate::Heap;
532531
use core::alloc::Layout;
533532
use std::mem::MaybeUninit;
534533
use std::prelude::v1::*;
535-
use crate::Heap;
536534

537535
#[repr(align(128))]
538536
struct Chonk<const N: usize> {
539-
data: [MaybeUninit<u8>; N]
537+
data: [MaybeUninit<u8>; N],
540538
}
541539

542540
impl<const N: usize> Chonk<N> {

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::prelude::v1::*;
55

66
#[repr(align(128))]
77
struct Chonk<const N: usize> {
8-
data: [MaybeUninit<u8>; N]
8+
data: [MaybeUninit<u8>; N],
99
}
1010

1111
impl<const N: usize> Chonk<N> {

0 commit comments

Comments
 (0)