使用all
判断所有字符是否为字母数字.
fn main() {
let name = String::from("Böb");
println!("{}", name.chars().all(char::is_alphanumeric));
}
chars
返回一个字符迭代器.all
返回true.is_alphanumeric
判断其是否为字母数字.对于任意字符集,可以将任何函数或代码块传递到all
.
有趣的是,the corresponding methods on str
were explicitly removed for subtle Unicode reasons.