String.into_ascii_lowercase

When using format! it would be convenient to be able to into_ascii_lowercase(self) -> String

The implementation is simple:

fn into_ascii_lowercase(self) -> String {
    self.make_ascii_lowercase();
    self
}

Because this is what my code looks like, and not having into_ascii_lowercase makes it rather painful: (but maybe the compiler can optimize the allocation out)

impl std::fmt::Display for AudioFormat {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match *self {
            default @ _ => write!(f, "{}", format!("{:?}", default).to_ascii_lowercase()),
        }
    }
}

(as seen in mpv-audio crate.)

That would be nice indeed.

BTW, there’s f.write_str() instead of write!(f, "{}").

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