Skip to content

Update std::array::from_fn example comment #156102

@reddevilmidzy

Description

@reddevilmidzy

Location (URL)

https://doc.rust-lang.org/core/array/fn.from_fn.html

/// You can also capture things, for example to create an array full of clones
/// where you can't just use `[item; N]` because it's not `Copy`:
/// ```
/// # // TBH `array::repeat` would be better for this, but it's not stable yet.
/// let my_string = String::from("Hello");
/// let clones: [String; 42] = std::array::from_fn(|_| my_string.clone());
/// assert!(clones.iter().all(|x| *x == my_string));
/// ```

It is not immediately visible to the user, but when the code is executed, comments follow in the playground.

Summary

std::array::repeat is now stable, so it seems necessary to update the comment or revise the example.

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

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