summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-06 12:33:15 -0700
committerGitHub <noreply@github.com>2021-10-06 12:33:15 -0700
commit91e3b5172ce53ff957b0955533f4b3cc39aebf56 (patch)
tree9c6817402f7fb3a87e177f4a959819f8c0edd8ef
parent1e3b5d6725a84b2060f66e61a59f33ad12aa17f8 (diff)
parentb2e4e59fbe201ff23fd2911f2650827ad46902b9 (diff)
downloadrust-91e3b5172ce53ff957b0955533f4b3cc39aebf56.tar.gz
Rollup merge of #89050 - DeveloperC286:drain_fields_to_private, r=joshtriplett
refactor: VecDeques Drain fields to private Made the fields of VecDeque's Drain private by creating a Drain::new(...) function to create a new instance of Drain and migrating usage to use Drain::new(...).
-rw-r--r--library/alloc/src/collections/vec_deque/drain.rs19
-rw-r--r--library/alloc/src/collections/vec_deque/mod.rs24
2 files changed, 26 insertions, 17 deletions
diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs
index dfa0227dea3..05f94da6de7 100644
--- a/library/alloc/src/collections/vec_deque/drain.rs
+++ b/library/alloc/src/collections/vec_deque/drain.rs
@@ -18,10 +18,21 @@ pub struct Drain<
T: 'a,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
> {
- pub(crate) after_tail: usize,
- pub(crate) after_head: usize,
- pub(crate) iter: Iter<'a, T>,
- pub(crate) deque: NonNull<VecDeque<T, A>>,
+ after_tail: usize,
+ after_head: usize,
+ iter: Iter<'a, T>,
+ deque: NonNull<VecDeque<T, A>>,
+}
+
+impl<'a, T, A: Allocator> Drain<'a, T, A> {
+ pub(super) unsafe fn new(
+ after_tail: usize,
+ after_head: usize,
+ iter: Iter<'a, T>,
+ deque: NonNull<VecDeque<T, A>>,
+ ) -> Self {
+ Drain { after_tail, after_head, iter, deque }
+ }
}
#[stable(feature = "collection_debug", since = "1.17.0")]
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs
index f4de2b2ebe5..ea3136cae42 100644
--- a/library/alloc/src/collections/vec_deque/mod.rs
+++ b/library/alloc/src/collections/vec_deque/mod.rs
@@ -1269,19 +1269,17 @@ impl<T, A: Allocator> VecDeque<T, A> {
// the drain is complete and the Drain destructor is run.
self.head = drain_tail;
- Drain {
- deque: NonNull::from(&mut *self),
- after_tail: drain_head,
- after_head: head,
- iter: Iter {
- tail: drain_tail,
- head: drain_head,
- // Crucially, we only create shared references from `self` here and read from
- // it. We do not write to `self` nor reborrow to a mutable reference.
- // Hence the raw pointer we created above, for `deque`, remains valid.
- ring: unsafe { self.buffer_as_slice() },
- },
- }
+ let deque = NonNull::from(&mut *self);
+ let iter = Iter {
+ tail: drain_tail,
+ head: drain_head,
+ // Crucially, we only create shared references from `self` here and read from
+ // it. We do not write to `self` nor reborrow to a mutable reference.
+ // Hence the raw pointer we created above, for `deque`, remains valid.
+ ring: unsafe { self.buffer_as_slice() },
+ };
+
+ unsafe { Drain::new(drain_head, head, iter, deque) }
}
/// Clears the `VecDeque`, removing all values.