What is character.is_ascii_digit() in Rust?
Overview
With the is_ascii_digit() character method, we can check if a character is an ASCII decimal digit in Rust. A digit is any number from 0 to 9.
Syntax
character.is_ascii_digit()
Syntax for is_ascii_digit()
Parameters
character: This is the character we want to check if it is an ASCII digit.
Return value
The value returned is a boolean. If the character is an ASCII digit, a true will be returned.
Example
fn main(){// check if some characters are really digits in some radixprintln!("{}", 'a'.is_ascii_digit()); // falseprintln!("{}", '1'.is_ascii_digit()); // trueprintln!("{}", '1'.is_ascii_digit()); // trueprintln!("{}", 'c'.is_ascii_digit()); // falseprintln!("{}", 'f'.is_ascii_digit()); // falseprintln!("{}", 'f'.is_ascii_digit()); // false}
Explanation
- Lines 3–8: We check if some characters were ASCII digit characters using the
is_ascii_digit()method and then we print the results to the console.