#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum EndpointId {
ExteriorFace,
ReachLeft,
ReachRight,
PoolConnection,
StructureEndpoint,
Outlet,
Lateral,
SurfaceCell,
}
impl EndpointId {
pub fn id(&self) -> &'static str {
match self {
Self::ExteriorFace => "exterior-face",
Self::ReachLeft => "reach-left",
Self::ReachRight => "reach-right",
Self::PoolConnection => "pool-connection",
Self::StructureEndpoint => "structure-endpoint",
Self::Outlet => "outlet",
Self::Lateral => "lateral",
Self::SurfaceCell => "surface-cell",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum BoundaryKind {
Wall,
FluxPort,
Stage,
Discharge,
Exterior,
Transmissive,
QuiescentReservoir,
PoolConnection,
SubmergedOrifice,
SuppressedRectangularWeir,
PumpStoppedIsolated,
PumpRunning,
GateFixedOpening,
GatePrescribedOpening,
GateActuatedOpening,
PumpSampledControl,
PrescribedInflowRate,
PrescribedInflowVolume,
RunoffOutletNoFeedback,
Culvert,
}
impl BoundaryKind {
pub fn id(&self) -> &'static str {
match self {
Self::Wall => "wall",
Self::FluxPort => "flux-port",
Self::Stage => "stage",
Self::Discharge => "discharge",
Self::Exterior => "exterior",
Self::Transmissive => "transmissive",
Self::QuiescentReservoir => "quiescent-reservoir",
Self::PoolConnection => "pool-connection",
Self::SubmergedOrifice => "submerged-orifice",
Self::SuppressedRectangularWeir => "suppressed-rectangular-weir",
Self::PumpStoppedIsolated => "pump-stopped-isolated",
Self::PumpRunning => "pump-running",
Self::GateFixedOpening => "gate-fixed-opening",
Self::GatePrescribedOpening => "gate-prescribed-opening",
Self::GateActuatedOpening => "gate-actuated-opening",
Self::PumpSampledControl => "pump-sampled-control",
Self::PrescribedInflowRate => "prescribed-inflow-rate",
Self::PrescribedInflowVolume => "prescribed-inflow-volume",
Self::RunoffOutletNoFeedback => "runoff-outlet-no-feedback",
Self::Culvert => "culvert",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Endpoint {
pub id: EndpointId,
pub admitted: &'static [BoundaryKind],
}
impl Endpoint {
pub fn admits(&self, kind: BoundaryKind) -> bool {
self.admitted.contains(&kind)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::capability::id_check::assert_ids;
#[test]
fn endpoint_ids_are_unique_kebab_case() {
let all = [
EndpointId::ExteriorFace,
EndpointId::ReachLeft,
EndpointId::ReachRight,
EndpointId::PoolConnection,
EndpointId::StructureEndpoint,
EndpointId::Outlet,
EndpointId::Lateral,
EndpointId::SurfaceCell,
];
assert_ids(&all.map(|e| e.id()));
}
#[test]
fn boundary_ids_are_unique_kebab_case() {
let all = [
BoundaryKind::Wall,
BoundaryKind::FluxPort,
BoundaryKind::Stage,
BoundaryKind::Discharge,
BoundaryKind::Exterior,
BoundaryKind::Transmissive,
BoundaryKind::QuiescentReservoir,
BoundaryKind::PoolConnection,
BoundaryKind::SubmergedOrifice,
BoundaryKind::SuppressedRectangularWeir,
BoundaryKind::PumpStoppedIsolated,
BoundaryKind::PumpRunning,
BoundaryKind::GateFixedOpening,
BoundaryKind::GatePrescribedOpening,
BoundaryKind::GateActuatedOpening,
BoundaryKind::PumpSampledControl,
BoundaryKind::PrescribedInflowRate,
BoundaryKind::PrescribedInflowVolume,
BoundaryKind::RunoffOutletNoFeedback,
BoundaryKind::Culvert,
];
assert_ids(&all.map(|b| b.id()));
}
#[test]
fn controlled_structure_boundary_ids_are_frozen() {
for (kind, id) in [
(
BoundaryKind::GatePrescribedOpening,
"gate-prescribed-opening",
),
(BoundaryKind::GateActuatedOpening, "gate-actuated-opening"),
(BoundaryKind::PumpSampledControl, "pump-sampled-control"),
] {
assert_eq!(kind.id(), id);
}
}
#[test]
fn endpoint_admits_only_listed_kinds() {
let end = Endpoint {
id: EndpointId::ReachLeft,
admitted: &[BoundaryKind::Wall, BoundaryKind::Stage],
};
assert!(end.admits(BoundaryKind::Wall));
assert!(end.admits(BoundaryKind::Stage));
assert!(!end.admits(BoundaryKind::Discharge));
}
}