#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PhysicalState {
Gas,
Liquid,
Solid,
Condensed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NistFallbackPolicy {
Disabled,
ExactRequestedState,
LegacyGasDefault,
}
impl NistFallbackPolicy {
pub const fn enabled(self) -> bool {
!matches!(self, Self::Disabled)
}
}
impl PhysicalState {
pub const fn accepts(self, observed: Self) -> bool {
matches!(
(self, observed),
(Self::Gas, Self::Gas)
| (Self::Liquid, Self::Liquid)
| (Self::Solid, Self::Solid)
| (
Self::Condensed,
Self::Liquid | Self::Solid | Self::Condensed
)
| (Self::Liquid | Self::Solid, Self::Condensed)
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThermoRecordQuery {
substance: String,
physical_state: Option<PhysicalState>,
}
impl ThermoRecordQuery {
pub fn new(substance: impl Into<String>) -> Self {
Self {
substance: substance.into(),
physical_state: None,
}
}
pub fn with_physical_state(mut self, physical_state: PhysicalState) -> Self {
self.physical_state = Some(physical_state);
self
}
pub fn with_physical_state_opt(mut self, physical_state: Option<PhysicalState>) -> Self {
self.physical_state = physical_state;
self
}
pub fn substance(&self) -> &str {
&self.substance
}
pub const fn physical_state(&self) -> Option<PhysicalState> {
self.physical_state
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PhysicalStateEvidence {
KeyConvention,
LibraryDefault,
}
#[cfg(test)]
mod tests {
use super::{NistFallbackPolicy, PhysicalState};
#[test]
fn exact_state_policy_is_the_only_non_legacy_enabled_choice() {
assert!(!NistFallbackPolicy::Disabled.enabled());
assert!(NistFallbackPolicy::ExactRequestedState.enabled());
assert!(NistFallbackPolicy::LegacyGasDefault.enabled());
}
#[test]
fn physical_state_acceptance_does_not_widen_liquid_or_solid_requests() {
assert!(PhysicalState::Liquid.accepts(PhysicalState::Liquid));
assert!(!PhysicalState::Liquid.accepts(PhysicalState::Gas));
assert!(PhysicalState::Solid.accepts(PhysicalState::Solid));
assert!(!PhysicalState::Solid.accepts(PhysicalState::Gas));
}
}