We use the is_ascii_graphic() method to check if a character is an ASCII graphic character. A graphic character is a character that is to be written, printed, shown, etc., in a way that humans can understand. ASCII is a popular encoding for information and communication among computers.
character.is_ascii_graphic()
character: This is the character we want to check to see if it is an ASCII graphic character.
The value returned is a Boolean value. If the character is an ASCII graphic character, then a true will be returned. Otherwise, a false is returned.
fn main(){// create some characterslet char1 = 't';let char2 = '❤'; // non ASCIIlet char3 = '☀'; // non ASCIIlet char4 = 'w';let char5 = 'n';// check if characters are ascii graphic charactersprintln!("{} is ASCII? {}", char1, char1.is_ascii_graphic()); // trueprintln!("{} is ASCII? {}", char2, char2.is_ascii_graphic()); // falseprintln!("{} is ASCII? {}", char3, char3.is_ascii_graphic()); // falseprintln!("{} is ASCII? {}", char4, char4.is_ascii_graphic()); // trueprintln!("{} is ASCII? {}", char5, char5.is_ascii_graphic()); // true}
char1 , char2 , char3 , char4 , char5).