-
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
Can one Borrow Vec<T, A> as [T]? #96
Comments
At the language level, yes this is absolutely possible. A slice has nothing to do with the allocator its memory might have come from, so Borrow can be generic over all allocators. The fact that it isn't written this way yet is just that the standard library hasn't developed enough. |
The implementation is based on https://doc.rust-lang.org/1.59.0/src/alloc/vec/mod.rs.html#2515-2522 impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> { So I would expect no issue with your proposed changed. Feel free to send a PR. |
Thanks! I haven't done any PRs to rust-lang/rust yet, but I'll try and make it happen in the near future :) |
…r=Mark-Simulacrum Borrow Vec<T, A> as [T] Hello all, When `Vec` was parametrized with `A`, the `Borrow` impls were omitted and currently `Vec<T, A>` can't be borrowed as `[T]`. This PR fixes that. This was probably missed, because the `Borrow` impls are in a different file - `src/alloc/slice.rs`. We briefly discussed this here: rust-lang/wg-allocators#96 and I was told to go ahead and make a PR :) I tested this by building the toolchain and building my code that needed the `Borrow` impl against it, but let me know if I should add any tests to this PR.
This got merged a few hours ago, closing |
…mulacrum Borrow Vec<T, A> as [T] Hello all, When `Vec` was parametrized with `A`, the `Borrow` impls were omitted and currently `Vec<T, A>` can't be borrowed as `[T]`. This PR fixes that. This was probably missed, because the `Borrow` impls are in a different file - `src/alloc/slice.rs`. We briefly discussed this here: rust-lang/wg-allocators#96 and I was told to go ahead and make a PR :) I tested this by building the toolchain and building my code that needed the `Borrow` impl against it, but let me know if I should add any tests to this PR.
Hello, my favorite Rust WG :))
At least as of nightly-2022-02-20,
Vec<T, A>
does not borrow as[T]
, onlyVec<T, Global>
does.From
src/alloc/slice.rs
:Which I guess could be:
Is this just a missing feature, or is there something fundamental afoot here?
(Need this for querying a hashmap with keys that are
String<A>
Vec<u8, A>
... btw anything I can do to makeString<A>
happen?)The text was updated successfully, but these errors were encountered: