-
Notifications
You must be signed in to change notification settings - Fork 9
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
Tracking Issue for structs which needs an allocator #7
Comments
I've started in rust-lang/rust#60703 . |
@ObsidianMinor has asked about the (38183) Allocator aware std traits - rust-lang - Zulip
Any reason this issue couldn't also accomodate |
Thoughts on |
@lachlansneff: What would your motivation be for splitting into another trait? |
Adding it to |
I think this should be added to the list in #15. |
However, as @SimonSapin noticed in #15 (comment), it's probably fine to add them at a later point. |
Okay. I'm guessing it'd look something like this? pub trait CloneIn {
type Alloc: Alloc;
fn clone_in(&self, allocator: Self::Alloc) -> T;
} |
Wouldn't just calling regular |
@Amanieu, how could it produce a |
@ErichDonGubler, I don't think it'd need a pub trait CloneIn {
type This<A: Alloc>;
fn clone_in<A: Alloc>(&self, allocator: A) -> Self::This<A>;
} This won't be possible until generic associated types, maybe there's another way of doing it? |
I was thinking something like pub trait CloneIn<A: Alloc> {
type Cloned;
fn clone_in(&self, allocator: A) -> Self::Cloned;
} Then you can implement it like impl<S, A: Alloc> CloneIn<A> for String<S> {
type Cloned = String<A>;
fn clone_in(&self, allocator: A) -> Self::Cloned {
String { vec: self.vec.clone_in(allocator) }
}
} |
I had this in mind: pub trait CloneIn<B: BuildAllocRef>: Sized
where
B::Ref: AllocRef,
{
fn clone_in(&self, a: B::Ref) -> Self
where
B::Ref: AllocRef<Error = crate::Never>;
fn try_clone_in(&self, a: B::Ref) -> Result<Self, <B::Ref as AllocRef>::Error>;
} But this has to be enhanced by an associative Self type. I think this should be discussed in #15 or in a new Issue. |
How would you add this method to IIUC what you are proposing, what would something like this do let x: Vec<T, A>;
let y: Vec<T, U> = x.clone_in(); if (*) I can imagine that we either have |
can't we make the
|
@95th You would need to return a different type than |
@gnzlbg you're right sorry.. A type based on generic param.. Edit: I realize the problem with this |
Do we also need to associate an allocator for owned strings types from |
On Sonntag, 10. November 2019 23:23:43 CET Qifan Lu wrote:
Do we also need to associate an allocator for owned strings types from
`std::ffi` module? That will include `CString` and `OSString`...
Adding an associated allocator to `CString` should be pretty straightforward,
as it's basically a `Box<[u8]>`. `OSString` depends on the Os, but this
shouldn't be a problem as well. Based on this, also `PathBuf` may should get
an allocator, too. All three have a low priority at time of writing though.
|
Currently, there is a PR upstream for cc @exrook |
When can we put |
I just answered the question right above. And my fat fingers clicked the wrong button :D |
@TimDiekmann I have just sent a PR for |
…Amanieu Add support for custom allocator in `VecDeque` This follows the [roadmap](rust-lang/wg-allocators#7) of the allocator WG to add custom allocators to collections. `@rustbot` modify labels: +A-allocators +T-libs
@TimDiekmann I made a PR for |
BTreeMap: Support custom allocators (v1.5) Related: rust-lang/wg-allocators#7 https://github.com/TimDiekmann/alloc-wg Blocked on: ~~rust-lang#77187~~ ~~rust-lang#78459~~ ~~rust-lang#95036~~ previous: rust-lang#77438
BTreeMap: Support custom allocators (v1.5) Related: rust-lang/wg-allocators#7 https://github.com/TimDiekmann/alloc-wg Blocked on: ~~rust-lang#77187~~ ~~rust-lang#78459~~ ~~rust-lang#95036~~ previous: rust-lang#77438
BTreeMap: Support custom allocators (v1.5) Related: rust-lang/wg-allocators#7 https://github.com/TimDiekmann/alloc-wg Blocked on: ~~rust-lang#77187~~ ~~rust-lang#78459~~ ~~rust-lang#95036~~ previous: rust-lang#77438
I might have a usecase for I notice there is no linked issue. If I want to add this, should I create an issue in |
I think you can just go ahead and write a pull request for it. All the allocators are under the #32838 tracking issue. |
BTreeMap: Support custom allocators (v1.5) Related: rust-lang/wg-allocators#7 https://github.com/TimDiekmann/alloc-wg Blocked on: ~~#77187~~ ~~#78459~~ ~~#95036~~ previous: #77438
@TimDiekmann I have a PR for |
Thanks, updated! |
Oh, I didn't realize I had to post back here, but I made a PR for |
There are a few changes to the list in the issue - @TimDiekmann would you want to update these items?
|
Thank you, I updated the comment. |
Make BinaryHeap parametric over Allocator Tracking issue: rust-lang#32838 Related: rust-lang/wg-allocators#7 This parametrizes `BinaryHeap` with `A`, similarly to how other collections are parametrized. A couple things I left out: ``` BinaryHeap::append Currently requires both structures to have the same allocator type. Could change, but depends on Vec::append, which has the same constraints. impl<T: Ord> Default for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord> FromIterator<T> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. unsafe impl<I> AsVecIntoIter for IntoIter<I> AsVecIntoIter is not allocator aware, and I didn't dare change it without guidance. Is this something important? ``` I've seen very few tests for allocator_api in general, but I'd like to at least test this on some usage code in my projects before moving forward. EDIT: Updated the list of impls and functions that are not affected by this. `BinaryHeap` no longer has a `SpecExtend` impl, and prior work made implementing `Extend` possible.
Rc and Arc just landed! rust-lang/rust#89132 (comment) |
Make BinaryHeap parametric over Allocator Tracking issue: #32838 Related: rust-lang/wg-allocators#7 This parametrizes `BinaryHeap` with `A`, similarly to how other collections are parametrized. A couple things I left out: ``` BinaryHeap::append Currently requires both structures to have the same allocator type. Could change, but depends on Vec::append, which has the same constraints. impl<T: Ord> Default for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord> FromIterator<T> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. unsafe impl<I> AsVecIntoIter for IntoIter<I> AsVecIntoIter is not allocator aware, and I didn't dare change it without guidance. Is this something important? ``` I've seen very few tests for allocator_api in general, but I'd like to at least test this on some usage code in my projects before moving forward. EDIT: Updated the list of impls and functions that are not affected by this. `BinaryHeap` no longer has a `SpecExtend` impl, and prior work made implementing `Extend` possible.
Make BinaryHeap parametric over Allocator Tracking issue: #32838 Related: rust-lang/wg-allocators#7 This parametrizes `BinaryHeap` with `A`, similarly to how other collections are parametrized. A couple things I left out: ``` BinaryHeap::append Currently requires both structures to have the same allocator type. Could change, but depends on Vec::append, which has the same constraints. impl<T: Ord> Default for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord> FromIterator<T> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. unsafe impl<I> AsVecIntoIter for IntoIter<I> AsVecIntoIter is not allocator aware, and I didn't dare change it without guidance. Is this something important? ``` I've seen very few tests for allocator_api in general, but I'd like to at least test this on some usage code in my projects before moving forward. EDIT: Updated the list of impls and functions that are not affected by this. `BinaryHeap` no longer has a `SpecExtend` impl, and prior work made implementing `Extend` possible.
This WG wants to associate an allocator for all suitable structs. This issue tracks those structs, which are covered so far (non-exhaustive list):
Box<T, A>
: Support custom allocators inBox
rust#77187Rc<T, A>
: Add support for allocators inRc
&Arc
rust#89132Arc<T, A>
: Add support for allocators inRc
&Arc
rust#89132String<A>
: [WIP] Add support for custom allocator forString
rust#101551CString<A>
: Add support for custom allocator for(C)String
rust#79500Vec<T, A>
: Add support for custom allocators inVec
rust#78461VecDeque<T, A>
: Add support for custom allocator inVecDeque
rust#86595LinkedList<T, A>
: Add support for allocators inLinkedList
rust#103093HashMap<K, V, S, A>
: Parametrize RawTable, HashSet and HashMap over an allocator hashbrown#133BTreeMap<K, V, A>
: BTreeMap: Support custom allocators (v1.5) rust#98103HashSet<T, S, A>
BTreeSet<T, A>
: BTreeMap: Support custom allocators (v1.5) rust#98103BinaryHeap<T, A>
: Make BinaryHeap parametric over Allocator rust#99339OsString<A>
)PathBuf<A>
)The text was updated successfully, but these errors were encountered: