Module kaydle_primitives::number
source · [−]Expand description
Parsers and utility types for parsing KDL numbers. While KDL doesn’t distinguish between floats and integers, or signed and unsigned numbers, this module uses some simple logic to detect different integer types, to aid with deserialization.
Number type logic
Currently, we use a simple set of rules to decide if a KDL number should be
parsed as an i64
, u64
, or f64
:
- If the number contains a fractional part or exponent, it’s unconditionally
parsed as an
f64
. - Otherwise, if it’s negative, it’s parsed as an
i64
. - Otherwise, it’s parsed as a
u64
.
These rules may change in the future. Possible improvements:
- If it includes an exponent, it might be an integer, even if it includes a fractional parts.
- If it’s an integer but it overflows an
i64
oru64
, it could be stored in anf64
instead. - It’s also possible we could use type hints (from serde or KDL annotations) to guide the parse as well.
Structs
A Bounds error occurred during number parsing. This type is incomplete and will grow in the future.
Enums
A KDL integer, which is either signed or unsigned. In practice, we always parse positive integers as unsigned and negative integers as signed.
A KDL Number. The KDL spec doesn’t distinguish between integers and floats, or between signed an unsigned numbers, but kaydle uses a heuristic to pick a type for deserialization purposes.
The parsed sign of a number
Traits
Helper trait for building or recognizing integers.
Trait for building KDL numbers
Functions
Parse a KDL number