Skip to content

Tracking Issue for Vec::from_elem and Vec::from_elem_in #164215

Open

Description

@Gelbpunkt

Feature gate: #![feature(vec_from_elem)]

This is a tracking issue for Vec::from_elem and Vec::from_elem_in.

These two methods allow creating a Vec that contains a specific element n times. The element must implement Clone for this. Internally, the methods can make use of specialization to make this operation more efficient than Vec::new followed by Vec::resize, for example when the element is zero, which will result in a single call to calloc instead of malloc + memset.

Public API

impl <T: Clone> Vec<T, Global> {
    pub fn from_elem(elem: T, n: usize) -> Self;
}

impl <T: Clone, A: Allocator> Vec<T, A> {
    pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Self;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions