-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for custom allocator in VecDeque
#86595
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
__impl_slice_eq1! { [const N: usize] VecDeque<A>, [B; N], } | ||
__impl_slice_eq1! { [const N: usize] VecDeque<A>, &[B; N], } | ||
__impl_slice_eq1! { [const N: usize] VecDeque<A>, &mut [B; N], } | ||
__impl_slice_eq1! { [] VecDeque<T, A>, Vec<U, A>, } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why do you require both to come from the same allocator? Just comparing them shouldn't do any reallocation, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all function potentially mixing allocators, while I agree that allowing it would be great, current APIs (eg for Vec
) do not seem to go in this direction.
There may be a reason I don't know for this choice, but I chose consistency anyway. If the opposite is decided, I'll be happy to change this.
impl<A: PartialEq> PartialEq for VecDeque<A> { | ||
fn eq(&self, other: &VecDeque<A>) -> bool { | ||
impl<T: PartialEq, A: Allocator> PartialEq for VecDeque<T, A> { | ||
fn eq(&self, other: &Self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: why require the same allocator? Is it required by the trait definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required by the definition (only for Eq
), but this is what Vec
does, so I did the same.
self.get_mut(index).expect("Out of bounds access") | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A> FromIterator<A> for VecDeque<A> { | ||
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> VecDeque<A> { | ||
impl<T> FromIterator<T> for VecDeque<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to add an A: Allocator parameter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure about this one, as adding a generic parameter could break inference. So I referred to what Vec
does and did the same.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_list().entries(self).finish() | ||
} | ||
} | ||
|
||
#[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] | ||
impl<T> From<Vec<T>> for VecDeque<T> { | ||
impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: why require the same allocator?
VecDeque { tail: 0, head: len, buf } | ||
} | ||
} | ||
} | ||
|
||
#[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] | ||
impl<T> From<VecDeque<T>> for Vec<T> { | ||
impl<T, A: Allocator> From<VecDeque<T, A>> for Vec<T, A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: why require the same allocator?
@@ -25,7 +27,7 @@ pub struct PairSlices<'a, 'b, T> { | |||
} | |||
|
|||
impl<'a, 'b, T> PairSlices<'a, 'b, T> { | |||
pub fn from(to: &'a mut VecDeque<T>, from: &'b VecDeque<T>) -> Self { | |||
pub fn from<A: Allocator>(to: &'a mut VecDeque<T, A>, from: &'b VecDeque<T, A>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: why require the same allocator?
This comment has been minimized.
This comment has been minimized.
4b52881
to
821b4b8
Compare
☔ The latest upstream changes (presumably #87366) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @Amanieu |
821b4b8
to
19318e6
Compare
I'm happy with the changes since it mirrors what @bors r+ |
📌 Commit 19318e6 has been approved by |
⌛ Testing commit 19318e6 with merge ca1bb41863911446e5f687c523052113c7716d9e... |
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 8987b74 has been approved by |
☀️ Test successful - checks-actions |
This follows the roadmap of the allocator WG to add custom allocators to collections.
@rustbot modify labels: +A-allocators +T-libs