Fn char::as_ascii(self) -> Option<u8>

Why doesn't this exist? There is a nice little is_ascii method but no way to extract the result (that I can see).

Use-case: https://github.com/rust-random/rand/pull/935

1 Like

Can you cast char as u8 after checking it's ASCII? ASCII is a subset of UTF-8, so it doesn't need any fancy conversion.

Aha, I forgot that char is a fundamental type and was looking for a TryFrom implementation.

This question is better asked on users.rust-lang.org

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