Skip to content

Commit 0ce28cb

Browse files
committed
Clarify contract for iter_from methods
1 parent e3a928f commit 0ce28cb

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/raw/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,23 +1002,26 @@ impl<T> RawTable<T> {
10021002
}
10031003

10041004
/// Returns an iterator which removes all elements from the table without
1005-
/// freeing the memory. It is up to the caller to ensure that the `RawTable`
1006-
/// outlives the `RawDrain`. Because we cannot make the `next` method unsafe
1007-
/// on the `RawDrain`, we have to make the `drain` method unsafe.
1005+
/// freeing the memory.
1006+
///
1007+
/// It is up to the caller to ensure that the `RawTable` outlives the `RawDrain`.
1008+
/// Because we cannot make the `next` method unsafe on the `RawDrain`,
1009+
/// we have to make the `drain` method unsafe.
10081010
#[cfg_attr(feature = "inline-more", inline)]
10091011
pub unsafe fn drain(&mut self) -> RawDrain<'_, T> {
10101012
let iter = self.iter();
10111013
self.drain_iter_from(iter)
10121014
}
10131015

10141016
/// Returns an iterator which removes all elements from the table without
1015-
/// freeing the memory. It is up to the caller to ensure that the `RawTable`
1016-
/// outlives the `RawDrain`. Because we cannot make the `next` method unsafe
1017-
/// on the `RawDrain`, we have to make the `drain` method unsafe.
1017+
/// freeing the memory.
10181018
///
1019-
/// Iteration starts at the provided iterator's current location.
1019+
/// It is up to the caller to ensure that the `RawTable` outlives the `RawDrain`.
1020+
/// Because we cannot make the `next` method unsafe on the `RawDrain`,
1021+
/// we have to make the `drain` method unsafe.
10201022
///
1021-
/// This method panics if the given iterator does not cover all items remaining in the table.
1023+
/// Iteration starts at the provided iterator's current location.
1024+
/// You must ensure that the iterator covers all items that remain in the table.
10221025
#[cfg_attr(feature = "inline-more", inline)]
10231026
pub unsafe fn drain_iter_from(&mut self, iter: RawIter<T>) -> RawDrain<'_, T> {
10241027
debug_assert_eq!(iter.len(), self.len());
@@ -1032,9 +1035,12 @@ impl<T> RawTable<T> {
10321035

10331036
/// Returns an iterator which consumes all elements from the table.
10341037
///
1035-
/// Iteration starts at the provided iterator's current location.
1038+
/// It is up to the caller to ensure that the `RawTable` outlives the `RawIntoIter`.
1039+
/// Because we cannot make the `next` method unsafe on the `RawIntoIter`,
1040+
/// we have to make the `into_iter_from` method unsafe.
10361041
///
1037-
/// This method panics if the given iterator does not cover all items remaining in the table.
1042+
/// Iteration starts at the provided iterator's current location.
1043+
/// You must ensure that the iterator covers all items that remain in the table.
10381044
pub unsafe fn into_iter_from(self, iter: RawIter<T>) -> RawIntoIter<T> {
10391045
debug_assert_eq!(iter.len(), self.len());
10401046

0 commit comments

Comments
 (0)