Skip to content
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

char::try_to_ascii ? #71683

Closed
leonardo-m opened this issue Apr 29, 2020 · 1 comment
Closed

char::try_to_ascii ? #71683

leonardo-m opened this issue Apr 29, 2020 · 1 comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

A simple method that could be useful:

char::try_to_ascii() -> Option<u8>;

related to char::is_ascii and char::to_ascii_lowercase/uppercase. Its purpose is to avoid some 'as' casts in user code:

if let Some(c) = c.try_to_ascii() {
    let order = c.to_ascii_uppercase() - b'A';

A simple implementation could be:

#[inline]
pub const fn try_to_ascii(&self) -> Option<u8> {
    if *self as u32 <= 0x7F {
        Some(*self as u8)
    } else {
        None
    }
}
@Alexendoo Alexendoo added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 29, 2020
@fmease
Copy link
Member

fmease commented Dec 21, 2024

Closing in favor of #110998 which currently includes char::as_ascii (fn(self: &str) -> Option<AsciiChar>).

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2024
@fmease fmease closed this as completed Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants