Skip to content

Commit cf9d4c2

Browse files
VecDeque use cases have COOP_PREFERRED
1 parent 4dc9c1b commit cf9d4c2

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

library/alloc/src/collections/vec_deque/into_iter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ use super::VecDeque;
1717
pub struct IntoIter<
1818
T,
1919
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
20+
const COOP_PREFERRED: bool = true
2021
>
21-
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
22-
inner: VecDeque<T, A>,
22+
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
23+
inner: VecDeque<T, A, COOP_PREFERRED>,
2324
}
2425

25-
impl<T, A: Allocator> IntoIter<T, A>
26+
impl<T, A: Allocator, const COOP_PREFERRED: bool> IntoIter<T, A, COOP_PREFERRED>
2627
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
27-
pub(super) fn new(inner: VecDeque<T, A>) -> Self {
28+
pub(super) fn new(inner: VecDeque<T, A, COOP_PREFERRED>) -> Self {
2829
IntoIter { inner }
2930
}
3031

31-
pub(super) fn into_vecdeque(self) -> VecDeque<T, A> {
32+
pub(super) fn into_vecdeque(self) -> VecDeque<T, A, COOP_PREFERRED> {
3233
self.inner
3334
}
3435
}

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
153153
}
154154

155155
#[stable(feature = "rust1", since = "1.0.0")]
156-
impl<T> Default for VecDeque<T> {
156+
impl<T, const COOP_PREFERRED: bool = true> Default for VecDeque<T, Global, COOP_PREFERRED> {
157157
/// Creates an empty deque.
158158
#[inline]
159-
fn default() -> VecDeque<T> {
159+
fn default() -> VecDeque<T, Global, COOP_PREFERRED> {
160160
VecDeque::new()
161161
}
162162
}
@@ -536,7 +536,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
536536
}
537537
}
538538

539-
impl<T> VecDeque<T> {
539+
impl<T, Global, const COOP_PREFERRED: bool> VecDeque<T, Global, COOP_PREFERRED>
540+
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
540541
/// Creates an empty deque.
541542
///
542543
/// # Examples
@@ -550,7 +551,7 @@ impl<T> VecDeque<T> {
550551
#[inline]
551552
#[stable(feature = "rust1", since = "1.0.0")]
552553
#[must_use]
553-
pub fn new() -> VecDeque<T> {
554+
pub fn new() -> VecDeque<T, Global, COOP_PREFERRED> {
554555
VecDeque::new_in(Global)
555556
}
556557

@@ -566,7 +567,7 @@ impl<T> VecDeque<T> {
566567
#[inline]
567568
#[stable(feature = "rust1", since = "1.0.0")]
568569
#[must_use]
569-
pub fn with_capacity(capacity: usize) -> VecDeque<T> {
570+
pub fn with_capacity(capacity: usize) -> VecDeque<T, Global, COOP_PREFERRED> {
570571
Self::with_capacity_in(capacity, Global)
571572
}
572573
}
@@ -584,7 +585,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
584585
/// ```
585586
#[inline]
586587
#[unstable(feature = "allocator_api", issue = "32838")]
587-
pub const fn new_in(alloc: A) -> VecDeque<T, A> {
588+
pub const fn new_in(alloc: A) -> VecDeque<T, A, COOP_PREFERRED> {
588589
VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) }
589590
}
590591

@@ -598,7 +599,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
598599
/// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
599600
/// ```
600601
#[unstable(feature = "allocator_api", issue = "32838")]
601-
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
602+
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A, COOP_PREFERRED> {
602603
VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) }
603604
}
604605

@@ -2889,7 +2890,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
28892890
/// assert_eq!(vec, [8, 9, 1, 2, 3, 4]);
28902891
/// assert_eq!(vec.as_ptr(), ptr);
28912892
/// ```
2892-
fn from(mut other: VecDeque<T, A>) -> Self {
2893+
fn from<const _VECDEQUE_COOP_PREFERRED: bool>(mut other: VecDeque<T, A, _VECDEQUE_COOP_PREFERRED>) -> Self {
28932894
other.make_contiguous();
28942895

28952896
unsafe {
@@ -2902,6 +2903,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
29022903
if other.head != 0 {
29032904
ptr::copy(buf.add(other.head), buf, len);
29042905
}
2906+
// @TODO:
29052907
Vec::from_raw_parts_in(buf, len, cap, alloc)
29062908
}
29072909
}

library/std/src/io/impls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ impl<A: Allocator> Write for Vec<u8, A> {
414414

415415
/// Read is implemented for `VecDeque<u8>` by consuming bytes from the front of the `VecDeque`.
416416
#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
417-
impl<A: Allocator> Read for VecDeque<u8, A> {
417+
impl<A: Allocator, const _COOP_PREFERRED: bool> Read for VecDeque<u8, A, _COOP_PREFERRED>
418+
where [(); co_alloc_metadata_num_slots_with_preference::<A>(_COOP_PREFERRED)]: {
418419
/// Fill `buf` with the contents of the "front" slice as returned by
419420
/// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are
420421
/// discontiguous, multiple calls to `read` will be needed to read the entire content.
@@ -438,7 +439,8 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
438439

439440
/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
440441
#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
441-
impl<A: Allocator> Write for VecDeque<u8, A> {
442+
impl<A: Allocator, const _COOP_PREFERRED: bool> Write for VecDeque<u8, A, _COOP_PREFERRED>
443+
where [(); co_alloc_metadata_num_slots_with_preference::<A>(_COOP_PREFERRED)]: {
442444
#[inline]
443445
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
444446
self.extend(buf);

0 commit comments

Comments
 (0)