pub struct Percent(/* private fields */);Expand description
Percentage in 0.0..=100.0. Construction outside that range returns
None so normalizers can translate to ParseError::InvalidValue.
Implementations§
Source§impl Percent
impl Percent
pub fn new(value: f32) -> Option<Self>
Sourcepub fn from_f64(value: f64) -> Option<Self>
pub fn from_f64(value: f64) -> Option<Self>
Construct from an f64 (JSON’s native number width). Range check
runs before narrowing, so values like 100.0000001 that would
round down to 100.0 in the cast are rejected rather than silently
accepted.
Sourcepub fn from_f64_clamped(value: f64) -> Option<Self>
pub fn from_f64_clamped(value: f64) -> Option<Self>
Construct from an f64, clamping finite out-of-range values into
0.0..=100.0. Returns None only for NaN. Use this when a field’s
upstream producer is known to emit values slightly past 100 (e.g.
Claude Code’s context_window.used_percentage post-/compact,
see claude-code#37163). Callers that want visibility into the
clamp should compare the raw value against the range before
invoking and emit a diagnostic — this helper is silent.
pub fn value(self) -> f32
Sourcepub fn complement(self) -> Self
pub fn complement(self) -> Self
100.0 - self, always in-range.