pub enum RawRdReal {
Na,
Finite(f64),
Nan,
PositiveInfinity,
NegativeInfinity,
}Expand description
A single value in an R real vector.
The special values use dedicated variants so serde formats such as JSON
never collapse NA, NaN, and positive or negative infinity into the
same null representation. This guarantee depends on
Finite itself only ever holding an actual finite
payload – see its documentation for the invariant.
§Why the invariant is documented rather than enforced
Nothing at the type level stops a caller from constructing
Finite(f64::NAN) or Finite(f64::INFINITY). Leaving that unenforced
is a deliberate trade-off:
- Within this crate the only producer is the RDS lowering
(
lower_raw_realinrds.rs), which classifies every incoming value (NA/NaN/ positive or negative infinity / finite) into the matching variant before construction, so lowering can never produce a non-finiteFinite. - Empirically, real (double) vectors do not occur in real-world R help
databases at all: Rd trees consist of character data plus
string/integer/logical attributes (
Rd_tag,Rd_option,srcref,Rdfile,class,dynamicFlag,macro). A full scan of an installed corpus (46 packages, 3457 topics, covering both values and attributes) found zero double vectors. This type exists for completeness of the lossless raw mirror, not because such data is expected in practice. - For JSON specifically, the deserialize direction is already safe:
JSON numbers cannot express
NaNor infinities, and{"kind":"finite","value":null}fails to deserialize asf64. The unenforced direction is serialization of a hand-constructed non-finiteFinite(silently emitted asnull), and round-tripping through binary serde formats that can represent non-finite floats.
Given the above, enforcement (a validated newtype payload plus a
custom Deserialize) was deliberately deferred; if these raw types
ever become a supported input surface for external producers, that is
the intended hardening path.
Variants§
Na
R’s NA_real_ value.
Finite(f64)
A finite IEEE-754 value.
This variant must only hold a finite payload; NA, NaN, and the
two infinities have their own dedicated variants (Na,
Nan, PositiveInfinity,
NegativeInfinity). Constructing
Finite with a non-finite value violates this contract: nothing
prevents it at the type level, but the derived serde Serialize
impl would then encode it as JSON null (serde_json’s standard
treatment of non-finite floats), silently defeating the point of
keeping these variants separate. See the type-level documentation
for why this invariant is documented rather than enforced.
Nan
A non-NA IEEE-754 not-a-number value.
PositiveInfinity
Positive infinity.
NegativeInfinity
Negative infinity.