You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe we can consider the idea of them returning iterators, but those iterators implementing Display. That makes it easy to use them composably (without having to allocate a string) while also having the string available (the .to_string() method).
🔔 This issue is now entering its final comment period for stabilization 🔔
For now this FCP will be for returning a String as returning an Iterator which implements Display isn't found much elsewhere in the standard library, but FCP can help duke this out!
Given that we have char::escape_{default,unicode} already stabilized, these seem like natural things to stabilize as well. I also agree with returning String, because that's probably what you'll use most of the time. If the extra allocation really matters, then expecting the programmer to build the iterator themselves with the underlying methods on char seems pretty reasonable IMO.
I do admit that I find it strange that these methods are in std, but I have found them occasionally very useful.
Activity
AnthonyBroadCrawford commentedon Sep 21, 2015
@alexcrichton Mind if I take this issue?
alexcrichton commentedon Sep 22, 2015
@AnthonyBroadCrawford certainly! The workflow for this would probably look like:
Diggsey commentedon Sep 22, 2015
The reason given for why they're currently unstable says that they might be rewritten to return a char iterator instead?
bluss commentedon Sep 23, 2015
Maybe we can consider the idea of them returning iterators, but those iterators implementing
Display. That makes it easy to use them composably (without having to allocate a string) while also having the string available (the .to_string() method).Diggsey commentedon Sep 23, 2015
@bluss You can already do
.collect()on a char iterator to turn it into a string.bluss commentedon Sep 23, 2015
True. With
Displayyou can{}-format the escaped string without intermediateStringor write-each-char loop.alexcrichton commentedon Dec 17, 2015
🔔 This issue is now entering its final comment period for stabilization 🔔
For now this FCP will be for returning a
Stringas returning anIteratorwhich implementsDisplayisn't found much elsewhere in the standard library, but FCP can help duke this out!BurntSushi commentedon Jan 13, 2016
Given that we have
char::escape_{default,unicode}already stabilized, these seem like natural things to stabilize as well. I also agree with returningString, because that's probably what you'll use most of the time. If the extra allocation really matters, then expecting the programmer to build the iterator themselves with the underlying methods oncharseems pretty reasonable IMO.I do admit that I find it strange that these methods are in
std, but I have found them occasionally very useful.34 remaining items
Auto merge of #58051 - SimonSapin:str_escape, r=alexcrichton
SimonSapin commentedon Feb 13, 2019
Stabilized in #58051.
New return types for str::escape_* that impl Display and Iterator<char>
Stabilize str::escape_* methods
Auto merge of #58051 - SimonSapin:str_escape, r=alexcrichton