pub struct RelativeHumidity(/* private fields */);Expand description
A validated relative humidity.
It stores a PERCENT in [0, 100], and Self::fraction gives the same humidity in
[0, 1]. The two constructors name the unit at the call site, and there is deliberately no
From<f64>, so a bare number is never read in the wrong unit.
One rule, the sensor band (HUMIDITY_SENSOR_TOLERANCE_PERCENT): a reading up to 5 points
outside the range is the saturated or dry air it measures, stored as exactly 100 or 0, so it
flies exactly as that end does. Anything farther out, or not finite, is refused with an
AtmosphereError that reports the value unchanged.
use ballistics_engine::RelativeHumidity;
let from_percent = RelativeHumidity::try_percent(50.0).unwrap();
let from_fraction = RelativeHumidity::try_fraction(0.5).unwrap();
assert_eq!(from_percent, from_fraction);
assert_eq!(from_percent, RelativeHumidity::DEFAULT);
assert_eq!(from_fraction.percent(), 50.0);
assert_eq!(from_percent.fraction(), 0.5);
// A sensor reading in fog, or in very dry air, is that air.
assert_eq!(RelativeHumidity::try_percent(101.7).unwrap().percent(), 100.0);
assert_eq!(RelativeHumidity::try_percent(-2.0).unwrap(), RelativeHumidity::DRY);
assert_eq!(RelativeHumidity::try_fraction(1.03).unwrap().percent(), 100.0);
assert!(RelativeHumidity::try_percent(150.0).is_err());
assert!(RelativeHumidity::try_percent(105.0000001).is_err());
// A percent sent where a fraction belongs is refused, not read as 50 %.
assert!(RelativeHumidity::try_fraction(50.0).is_err());A bare f64 does not convert, because it does not say whether 0.5 means 50 % or 0.5 %
(E0277: no From<f64>):
use ballistics_engine::RelativeHumidity;
let humidity: RelativeHumidity = 0.5.into();Implementations§
Source§impl RelativeHumidity
impl RelativeHumidity
Sourcepub const DEFAULT: Self
pub const DEFAULT: Self
The default for an omitted humidity: DEFAULT_HUMIDITY_PERCENT, 50 %.
Sourcepub const FRACTION_BAND: (f64, f64) = HUMIDITY_FRACTION_BAND
pub const FRACTION_BAND: (f64, f64) = HUMIDITY_FRACTION_BAND
The lowest and the highest fraction Self::try_fraction accepts, both included: the
sensor band (HUMIDITY_SENSOR_TOLERANCE_PERCENT) in fraction units, exactly
(-0.05, 1.05).
For a schema that publishes the bounds the decoder enforces (the MCP server’s
relative_humidity), so the band it states is derived from the one number rather than
written out again.
Sourcepub fn try_percent(percent: f64) -> Result<Self, AtmosphereError>
pub fn try_percent(percent: f64) -> Result<Self, AtmosphereError>
A relative humidity given in PERCENT.
Accepts a finite percent from -5 to 105, both ends included (the sensor band,
HUMIDITY_SENSOR_TOLERANCE_PERCENT). A percent in 0.0..=100.0 is stored unchanged,
one above 100 as exactly 100 and one below 0 (or -0.0) as 0.0. Anything else is
refused, with field humidity_percent, the value unchanged, and reason
AtmosphereErrorReason::NotFinite or
AtmosphereErrorReason::HumidityPercentOutOfRange.
Sourcepub fn try_fraction(fraction: f64) -> Result<Self, AtmosphereError>
pub fn try_fraction(fraction: f64) -> Result<Self, AtmosphereError>
A relative humidity given as a FRACTION, the SI wire’s relative_humidity.
Accepts a finite fraction from -0.05 to 1.05, both ends included (the sensor band in
fraction units), and stores the fraction snapped into 0.0..=1.0 times 100: an
in-range fraction is fraction * 100.0, exact at 0, 0.5 and 1 and within one ulp of the
decimal percent elsewhere, one above 1 is exactly 100, one below 0 is 0. Anything else is
refused, with field relative_humidity, the value unchanged, and reason
AtmosphereErrorReason::NotFinite or
AtmosphereErrorReason::HumidityFractionOutOfRange; so a percent sent by mistake
(50.0) is an error rather than 5000 %.
Trait Implementations§
Source§impl Clone for RelativeHumidity
impl Clone for RelativeHumidity
Source§fn clone(&self) -> RelativeHumidity
fn clone(&self) -> RelativeHumidity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RelativeHumidity
impl Debug for RelativeHumidity
Source§impl PartialEq for RelativeHumidity
impl PartialEq for RelativeHumidity
impl Copy for RelativeHumidity
impl StructuralPartialEq for RelativeHumidity
Auto Trait Implementations§
impl Freeze for RelativeHumidity
impl RefUnwindSafe for RelativeHumidity
impl Send for RelativeHumidity
impl Sync for RelativeHumidity
impl Unpin for RelativeHumidity
impl UnwindSafe for RelativeHumidity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.