|
2 | 2 |
|
3 | 3 | use slab::*;
|
4 | 4 |
|
5 |
| -use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe}; |
| 5 | +use std::{ |
| 6 | + iter::FromIterator, |
| 7 | + panic::{catch_unwind, resume_unwind, AssertUnwindSafe}, |
| 8 | +}; |
6 | 9 |
|
7 | 10 | #[test]
|
8 | 11 | fn insert_get_remove_one() {
|
@@ -730,3 +733,37 @@ fn clone_from() {
|
730 | 733 | assert_eq!(iter2.next(), None);
|
731 | 734 | assert!(slab2.capacity() >= 10);
|
732 | 735 | }
|
| 736 | + |
| 737 | +#[test] |
| 738 | +fn get_disjoint_mut() { |
| 739 | + let mut slab = Slab::from_iter((0..5).enumerate()); |
| 740 | + slab.remove(1); |
| 741 | + slab.remove(3); |
| 742 | + |
| 743 | + assert_eq!(slab.get_disjoint_mut([]), Ok([])); |
| 744 | + |
| 745 | + assert_eq!( |
| 746 | + slab.get_disjoint_mut([4, 2, 0]).unwrap().map(|x| *x), |
| 747 | + [4, 2, 0] |
| 748 | + ); |
| 749 | + |
| 750 | + assert_eq!( |
| 751 | + slab.get_disjoint_mut([42, 2, 1, 2]), |
| 752 | + Err(GetDisjointMutError::OverlappingIndices) |
| 753 | + ); |
| 754 | + |
| 755 | + assert_eq!( |
| 756 | + slab.get_disjoint_mut([1, 5]), |
| 757 | + Err(GetDisjointMutError::IndexVacant) |
| 758 | + ); |
| 759 | + |
| 760 | + assert_eq!( |
| 761 | + slab.get_disjoint_mut([5, 1]), |
| 762 | + Err(GetDisjointMutError::IndexOutOfBounds) |
| 763 | + ); |
| 764 | + |
| 765 | + let [a, b] = slab.get_disjoint_mut([0, 4]).unwrap(); |
| 766 | + (*a, *b) = (*b, *a); |
| 767 | + assert_eq!(slab[0], 4); |
| 768 | + assert_eq!(slab[4], 0); |
| 769 | +} |
0 commit comments