Skip to content

Commit

Permalink
Add unstable sorting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed May 26, 2023
1 parent a7db6b2 commit 5ff9859
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,15 @@ impl<T> VecCell<T> {
T: Ord,
F: FnMut(&T, &T) -> Ordering,
{
assert_eq!(
self.borrows.get(),
0,
"Sorting requires that no item is currently borrowed"
);
assert!(
self.mut_borrow.get().is_none(),
"Sorting requires that no item is currently (mutably) borrowed"
);
self.inner.sort_unstable_by(|a, b| {
// SAFETY: self is borrowed mutably and a and b are not itself changed.
let a = unsafe { &*a.get() };
Expand Down Expand Up @@ -651,6 +660,15 @@ impl<T> VecCell<T> {
F: FnMut(&T) -> K,
K: Ord,
{
assert_eq!(
self.borrows.get(),
0,
"Sorting requires that no item is currently borrowed"
);
assert!(
self.mut_borrow.get().is_none(),
"Sorting requires that no item is currently (mutably) borrowed"
);
self.inner.sort_unstable_by(|a, b| {
// SAFETY: self is borrowed mutably and a and b are not itself changed.
let a = f(unsafe { &*a.get() });
Expand Down

0 comments on commit 5ff9859

Please # to comment.