-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method str::repeat(self, usize) -> String #36699
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
This method is called |
|
Thanks. Fixed by amending. Yes I'm letting the bots do the compiling for me. |
I have an interesting idea, would it make sense to add a |
@pmarcelll That sounds just like the existing |
Oh, I knew about |
Looks reasonable to me! I'd also be fine extending iterators/collections with more methods like this, but in isolation cc @rust-lang/libs |
Let's see if this works... @rfcbot disposition merge Only thing I see missing is a tracking issue, but we can fill that in when it's agreed to land. |
@rfcbot fcp merge |
FCP proposed with disposition to merge. Review requested from: No concerns currently listed. |
I'm fine with this convenience (though I feel like we explicitly cut away some things like this on the road to 1.0). |
All relevant subteam members have reviewed. No concerns remain. |
It is relatively simple to repeat a string n times: `(0..n).map(|_| s).collect::<String>()`. It becomes slightly more complicated to do it “right” (sizing the allocation up front), which warrants a method that does it for us. This method is useful in writing testcases, or when generating text. `format!()` can be used to repeat single characters, but not repeating strings like this.
Amended the commit to point to tracking issue #37079 |
@bors: r+ Thanks! |
📌 Commit 2b7222d has been approved by |
@bors rollup |
Add method str::repeat(self, usize) -> String It is relatively simple to repeat a string n times: `(0..n).map(|_| s).collect::<String>()`. It becomes slightly more complicated to do it “right” (sizing the allocation up front), which warrants a method that does it for us. This method is useful in writing testcases, or when generating text. `format!()` can be used to repeat single characters, but not repeating strings like this.
It has been one week since all blocks to the FCP were resolved. |
It is relatively simple to repeat a string n times:
(0..n).map(|_| s).collect::<String>()
. It becomes slightly morecomplicated to do it “right” (sizing the allocation up front), which
warrants a method that does it for us.
This method is useful in writing testcases, or when generating text.
format!()
can be used to repeat single characters, but not repeatingstrings like this.