pub trait IsNumeric {
    // Required method
    fn is_numeric(&self) -> bool;
}
Expand description

Method to check if the string may be parsed to an integer or float

Required Methods§

source

fn is_numeric(&self) -> bool

strict check on a numeric string before using .parse::() use trim() or correct_numeric_string() first for looser number validation This mirrors a similar function in PHP, but is will fail with spaces or any non-numeric characters other than a leading minus or a single decimal point For characters, is_numeric checks for decimal digit-equivalent characters e.g. let input_str = “-2389.49”; let optional_value = if input_str.is_numeric() { input_str.parse::() } else { None };

Implementations on Foreign Types§

source§

impl IsNumeric for str

Implementation for &str / String

source§

fn is_numeric(&self) -> bool

Check if the string may be parsed to a number This is a now a strict regex-free check Use trim() or correct_numeric_string() first for looser number validation

Implementors§