Skip to main content

hydr_core/capability/
source.rs

1//! Local water sources and sinks.
2
3/// Local source or sink that a component admits.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum SourceKind {
7    /// Rain on the surface.
8    Rain,
9    /// Runoff from impervious land.
10    ImperviousLand,
11    /// Infiltration by the modified Green-Ampt method.
12    ModifiedGreenAmpt,
13    /// Evaporation loss.
14    Evaporation,
15    /// Prescribed withdrawal.
16    Withdrawal,
17    /// Lateral inflow along a reach.
18    LateralInflow,
19    /// Lateral withdrawal along a reach.
20    LateralWithdrawal,
21    /// Volume exchanged with a coupled component.
22    ExchangeVolume,
23    /// Rain directly on a pool.
24    LocalPoolRain,
25    /// Local loss from a pool.
26    LocalPoolLoss,
27}
28
29impl SourceKind {
30    /// Returns the stable kebab-case id. Persisted decisions store it, so it never changes.
31    pub fn id(&self) -> &'static str {
32        match self {
33            Self::Rain => "rain",
34            Self::ImperviousLand => "impervious-land",
35            Self::ModifiedGreenAmpt => "modified-green-ampt",
36            Self::Evaporation => "evaporation",
37            Self::Withdrawal => "withdrawal",
38            Self::LateralInflow => "lateral-inflow",
39            Self::LateralWithdrawal => "lateral-withdrawal",
40            Self::ExchangeVolume => "exchange-volume",
41            Self::LocalPoolRain => "local-pool-rain",
42            Self::LocalPoolLoss => "local-pool-loss",
43        }
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50    use crate::capability::id_check::assert_ids;
51
52    #[test]
53    fn ids_are_unique_kebab_case() {
54        let all = [
55            SourceKind::Rain,
56            SourceKind::ImperviousLand,
57            SourceKind::ModifiedGreenAmpt,
58            SourceKind::Evaporation,
59            SourceKind::Withdrawal,
60            SourceKind::LateralInflow,
61            SourceKind::LateralWithdrawal,
62            SourceKind::ExchangeVolume,
63            SourceKind::LocalPoolRain,
64            SourceKind::LocalPoolLoss,
65        ];
66        assert_ids(&all.map(|s| s.id()));
67    }
68}