Closed yanchith closed 1 year ago
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 Index<RangeFull>
, which is implemented for all allocator types:
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 :)
This got merged a few hours ago, closing
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?)