In the function below, I match the first full character of a &str
, and if it is a *
, -
, or _
and if it is those that character is returned, and with the _
arm I want to check if the character is whitespace, and return 'a'
otherwise.
fn print_character(text: &str) {
let character: char = match text.chars().nth(0).unwrap() {
ch @ '*' | ch @ '-' | ch @ '_' => ch,
ch @ _ => {
if !ch.is_whitespace() {
return 'a';
}
' '
}
};
println!("{}", character);
}
When I run the code I get the error below:
error[E0308]: mismatched types
--> src/main.rs:6:24
|
6 | return 'a';
| ^^^ expected (), found char
|
= note: expected type `()`
found type `char`