Skip to content

Implement From<{&,&mut} [T; N]> for Vec<T> where T: Clone #220

Closed
@EFanZh

Description

@EFanZh

Proposal

Problem statement

Currently, we have From<{&,&mut} [T]> for Vec<T> where T: Clone, I think we can also implement From<{&,&mut} [T; N]> for Vec<T> where T: Clone.

Motivation, use-cases

Suppose I want to convert an &[[u32; 4]] value to a Vec<Vec<u32>> type. Currently, I can write:

  • items.iter().map(|item| item.to_vec()).collect::<Vec<_>>();
  • items.iter().copied().map(Vec::from).collect::<Vec<_>>();

I want to be able to write:

  • items.iter().map(Vec::from).collect::<Vec<_>>();

Solution sketches

Implement From<{&,&mut} [T; N]> for Vec<T> where T: Clone.

Links and related work

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions