Char
Char module: character classification and conversion utilities.
Wraps the built-in char_* primitives for idiomatic use. All predicates return Bool; conversions preserve the char type.
Functions
Returns the numeric value of a digit character (0-9). Panics if not a digit — use digit_value_opt for the fallible variant when the input may not be a digit.
Returns the numeric value of a digit character (0-9) as Some(n), or None if c is not an ASCII digit. Prefer this safe variant when the input comes from user data (file, network, form) — it's the "lookup-miss → Option" arm of the stdlib error-signaling policy.
Returns the one-byte string for byte value n, taken modulo 256 (so 256 yields byte 0, and -1 yields byte 255). A byte, not a code point: build a multi-byte UTF-8 character one byte at a time.
Returns the hex value of a hex digit (0-9, a-f, A-F). Panics if not a hex digit — use hex_digit_value_opt when the input might not be hex.
Returns the hex value of a hex digit (0-9, a-f, A-F) as Some(n), or None if c is not a hex digit. Safe variant for parsing untrusted hex strings.
Returns true if c is an ASCII letter (a-z or A-Z).
Returns true if c is an ASCII letter or digit.
Returns true if c is ASCII (code point 0-127).
Returns true if c is an ASCII digit (0-9).
Returns true if c is a hex digit (0-9, a-f, A-F).
Returns true if c is an ASCII lowercase letter (a-z).
Returns true if c is a printable ASCII character (code point 32-126).
Returns true if c is an ASCII uppercase letter (A-Z).
Returns true if c is an ASCII whitespace character (space, tab, newline, etc.).
Returns the value (0-255) of the first byte of c. A byte, not a code point: for multi-byte UTF-8 text this is the leading byte only.
Converts c to lowercase. Non-alphabetic chars are returned unchanged.
Returns a single-character string containing c.
Converts c to uppercase. Non-alphabetic chars are returned unchanged.