Skip to content

Tricky to construct a dynamically sized ~[T] #13658

@SiegeLord

Description

@SiegeLord

With the removal of ~[T] vector building functions by #13588, it is now very difficult to construct ~[T] with a size known at runtime. Currently I opted for this replacement of std::slice::from_elem:

fn from_elem<T: Clone>(size: uint, el: T) -> ~[T]
{
    use std::iter::Repeat;
    Repeat::new(el).take(size).collect()
}

but it is unclear to me if this workaround is not merely an oversight. Is the intention to make dynamically sized ~[T] impossible to construct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions