Trait NumbersLike

Source
pub trait NumbersLike {
    // Required method
    fn get(&self, input: &str) -> Option<Multiplier>;
}
Expand description

NumbersLike strings can occur where usually a number would occur in the source string

NumbersLike words or strings express a number as a word like one or next instead of 1 or half instead of 0.5 but also last instead of -1 etc. This symbolic number is defined as a Multiplier. In contrast to numbers, NumbersLike without a time unit are considered an error and therefore have to be followed by a time unit.

§Examples

use fundu_core::config::NumbersLike;
use fundu_core::time::Multiplier;

struct Numerals {}
impl NumbersLike for Numerals {
    fn get(&self, input: &str) -> Option<Multiplier> {
        match input {
            "one" | "next" => Some(Multiplier(1, 0)),
            "this" => Some(Multiplier(0, 0)),
            "last" => Some(Multiplier(-1, 0)),
            "half" => Some(Multiplier(5, -1)),
            _ => None,
        }
    }
}

let numerals = Numerals {};
assert_eq!(numerals.get("one"), Some(Multiplier(1, 0)));

Required Methods§

Source

fn get(&self, input: &str) -> Option<Multiplier>

Implementors§