summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeveloperC <DeveloperC@protonmail.com>2021-09-25 13:55:45 +0100
committerDeveloperC <DeveloperC@protonmail.com>2021-10-05 19:09:49 +0100
commit5af61cb114e4af46e5c1c6c97b4556d5f007536f (patch)
tree4cbcdf6d717af2004426542a8f184e1bd31e086e
parent25ec8273855fde2d72ae877b397e054de5300e10 (diff)
downloadrust-5af61cb114e4af46e5c1c6c97b4556d5f007536f.tar.gz
refactor: VecDeques IterMut fields to private
Made the fields of VecDeque's IterMut private by creating a IterMut::new(...) function to create a new instance of IterMut and migrating usage to use IterMut::new(...).
-rw-r--r--library/alloc/src/collections/vec_deque/iter_mut.rs19
-rw-r--r--library/alloc/src/collections/vec_deque/mod.rs18
2 files changed, 21 insertions, 16 deletions
diff --git a/library/alloc/src/collections/vec_deque/iter_mut.rs b/library/alloc/src/collections/vec_deque/iter_mut.rs
index 7700b31cf5b..31e6e3b06af 100644
--- a/library/alloc/src/collections/vec_deque/iter_mut.rs
+++ b/library/alloc/src/collections/vec_deque/iter_mut.rs
@@ -13,10 +13,21 @@ use super::{count, wrap_index, RingSlices};
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> {
// Internal safety invariant: the entire slice is dereferencable.
- pub(crate) ring: *mut [T],
- pub(crate) tail: usize,
- pub(crate) head: usize,
- pub(crate) phantom: PhantomData<&'a mut [T]>,
+ ring: *mut [T],
+ tail: usize,
+ head: usize,
+ phantom: PhantomData<&'a mut [T]>,
+}
+
+impl<'a, T> IterMut<'a, T> {
+ pub(super) unsafe fn new(
+ ring: *mut [T],
+ tail: usize,
+ head: usize,
+ phantom: PhantomData<&'a mut [T]>,
+ ) -> Self {
+ IterMut { ring, tail, head, phantom }
+ }
}
// SAFETY: we do nothing thread-local and there is no interior mutability,
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs
index f4de2b2ebe5..54fcb358ede 100644
--- a/library/alloc/src/collections/vec_deque/mod.rs
+++ b/library/alloc/src/collections/vec_deque/mod.rs
@@ -1000,12 +1000,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
// SAFETY: The internal `IterMut` safety invariant is established because the
// `ring` we create is a dereferencable slice for lifetime '_.
- IterMut {
- tail: self.tail,
- head: self.head,
- ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
- phantom: PhantomData,
- }
+ let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
+
+ unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) }
}
/// Returns a pair of slices which contain, in order, the contents of the
@@ -1192,12 +1189,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
// SAFETY: The internal `IterMut` safety invariant is established because the
// `ring` we create is a dereferencable slice for lifetime '_.
- IterMut {
- tail,
- head,
- ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
- phantom: PhantomData,
- }
+ let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
+
+ unsafe { IterMut::new(ring, tail, head, PhantomData) }
}
/// Creates a draining iterator that removes the specified range in the