Skip to content

Can one Borrow Vec<T, A> as [T]? #96

Closed
@yanchith

Description

@yanchith

Hello, my favorite Rust WG :))

At least as of nightly-2022-02-20, Vec<T, A> does not borrow as [T], only Vec<T, Global> does.

From src/alloc/slice.rs:

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Borrow<[T]> for Vec<T> {
    fn borrow(&self) -> &[T] {
        &self[..]
    }
}

Which I guess could be:

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A: Allocator> Borrow<[T]> for Vec<T, A> {
    fn borrow(&self) -> &[T] {
        &self[..]
    }
}

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 make String<A> happen?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions