Logo

Programming-Idioms

History of Idiom 137 > diff from v23 to v24

Edit summary for version 24 by freecoder:
[Rust] Map is_numeric directly

Version 23

2018-08-29, 14:51:47

Version 24

2018-12-17, 18:47:10

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Code
let b = s.chars().all(|c| c.is_numeric() );
Code
let b = s.chars().all(char::is_numeric);
Doc URL
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all
Doc URL
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=78903ab3c20c95d902dbdbeea140b01e