grippo 0.3.1

Grok, regex, CEL and scrubbing on typed primitives. Up to 9 times faster than the stock Rust regex.
Documentation
// Project:   grippo
// File:      src/parse/number.rs
// Purpose:   A numeric field's text as a typed number
// Language:  Rust
//
// License:   Apache-2.0
// Copyright: (c) 2026 HYPERI PTY LIMITED

//! A numeric field's text as a typed number.
//!
//! Parsers keep a number as the text the record held and hint it `Int` or
//! `Float`. [`FieldValue::number`] reads that text with the
//! [`NumberReading::Exact`](crate::number::NumberReading::Exact) rules under
//! the hint, so every sink that stores typed columns reads `07`, `-0` and a
//! 20-digit integer the same way.

use super::{FieldValue, Hint};
use crate::number::{Number, float, whole};

impl FieldValue<'_> {
    /// The value as a number, or `None` to keep the text.
    ///
    /// The hint says whole or float, never the spelling, so `3` and `3.5`
    /// under one hint don't make one field two kinds:
    ///
    /// - [`Hint::Int`]: a sign and digits. `Int` when it fits `i64`, `UInt`
    ///   past that when it fits `u64`, `None` beyond either end.
    /// - [`Hint::Float`]: digits with an optional point and exponent, as
    ///   `Float`. `None` when it rounds to an infinity.
    /// - Any other hint: `None`, whatever the text looks like.
    ///
    /// A leading `+` and leading zeros are read. Spaces, `inf`, `nan` and
    /// hex are not. `None` never means a bad record: the bytes are
    /// untouched, and a store that must be exact keeps them.
    ///
    /// Without a hint,
    /// [`NumberReading::Exact`](crate::number::NumberReading::Exact) picks
    /// whole or float from the spelling.
    #[must_use]
    pub fn number(&self) -> Option<Number> {
        match self.hint {
            Hint::Int => whole(&self.bytes).ok(),
            Hint::Float => float(&self.bytes).map(Number::Float),
            _ => None,
        }
    }
}

#[cfg(test)]
mod tests;