Skip to content

Commit

Permalink
drain_filter feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
L0uisc authored and mbrubeck committed Jun 15, 2023
1 parent c64344a commit fa77030
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ write = []
union = []
specialization = []
may_dangle = []
drain_filter = []

# UNSTABLE FEATURES (requires Rust nightly)
# Enable to use the #[debugger_visualizer] attribute.
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ impl<'a, T: 'a + Array> Drop for Drain<'a, T> {
}
}

#[cfg(feature = "drain_filter")]
/// An iterator which uses a closure to determine if an element should be removed.
///
/// Returned from [`SmallVec::drain_filter`][1].
Expand Down Expand Up @@ -437,6 +438,7 @@ where
panic_flag: bool,
}

#[cfg(feature = "drain_filter")]
impl <T, F> fmt::Debug for DrainFilter<'_, T, F>
where
F: FnMut(&mut T::Item) -> bool,
Expand All @@ -448,6 +450,7 @@ where
}
}

#[cfg(feature = "drain_filter")]
impl <T, F> Iterator for DrainFilter<'_, T, F>
where
F: FnMut(&mut T::Item) -> bool,
Expand Down Expand Up @@ -487,6 +490,7 @@ where
}
}

#[cfg(feature = "drain_filter")]
impl <T, F> Drop for DrainFilter<'_, T, F>
where
F: FnMut(&mut T::Item) -> bool,
Expand Down Expand Up @@ -974,6 +978,8 @@ impl<A: Array> SmallVec<A> {
}
}


#[cfg(feature = "drain_filter")]
/// Creates an iterator which uses a closure to determine if an element should be removed.
///
/// If the closure returns true, the element is removed and yielded. If the closure returns
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,10 @@ fn test_size() {
assert_eq!(24, size_of::<SmallVec<[u8; 8]>>());
}

// #[cfg(feature("drain_filter"))]
#[cfg(feature = "drain_filter")]
#[test]
fn drain_filter() {
let mut a: SmallVec<[u8; 2]> = SmallVec::from_slice(&[1u8, 2, 3, 4, 5, 6, 7, 8]);
let mut a: SmallVec<[u8; 2]> = smallvec![1u8, 2, 3, 4, 5, 6, 7, 8];

let b: SmallVec<[u8; 2]> = a.drain_filter(|x| *x % 3 == 0).collect();

Expand Down

0 comments on commit fa77030

Please sign in to comment.