Add `as_lowercase` et. al

There exists a method called str::to_lowercase that allocates a string with unicode case conversion. I propose adding a method called str::as_lowercase with the signature

impl str {
    fn as_lowercase(&self) -> impl Display + '_;

Using this method can avoid some allocations, which is perhaps most useful when allocation is not possible (no_std), but also in any performance-critical portion of code.

What are others' thoughts on this?


(edited) If you need fast lowercasing for equality and hashmap keys, there's:

Having it as a named type is handy, because it can be used as a key in a hashmap.


I can see how you would use unicase to compare strings, but I can't see how you would use it to create something that you can interpolate in a format string, that converts to lowercase on-the-fly.


True, but that's also a good idea for an implementation: create a wrapper class that you use only in println!() and friends which will format the string in lowercase without allocating, a bit like gpoint does for floating numbers.

Oops! You're right. I thought about other usages.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.