Skip to main content

hfx_core/
lib.rs

1//! Shared types and validation primitives for HFX artifacts.
2//!
3//! This crate defines the canonical in-memory representation of HFX
4//! domain concepts. All types enforce their invariants at construction
5//! time ("parse, don't validate"). No I/O — deserialization from
6//! Parquet/JSON/GeoTIFF is the responsibility of downstream crates.
7
8pub mod area;
9pub mod auxiliary;
10pub mod catchment;
11pub mod geo;
12pub mod graph;
13pub mod id;
14pub mod level;
15pub mod manifest;
16pub mod raster;
17pub mod snap;
18
19// --- Re-exports for ergonomic imports ---
20
21pub use area::{AreaKm2, MeasureError, Weight};
22pub use auxiliary::{AuxiliaryDecl, AuxiliaryError, AuxiliarySchemaId, BlessedAuxSchema};
23pub use catchment::CatchmentUnit;
24pub use geo::{BoundingBox, GeoError, Latitude, Longitude, OutletCoord, WkbGeometry};
25pub use graph::{AdjacencyRow, DrainageGraph, GraphError};
26pub use id::{IdError, SnapId, UnitId};
27pub use level::{Level, LevelError};
28pub use manifest::{
29    Crs, FormatVersion, Manifest, ManifestBuilder, ManifestError, Topology, UnitCount,
30    UpAreaAvailability,
31};
32pub use raster::{FlowDirEncoding, FlowDirEncodingError};
33pub use snap::{SnapError, SnapTarget, StemRole};
34
35/// Trait for types that carry a spatial bounding box.
36///
37/// Enables generic spatial filtering over catchments or any future artifact row type.
38pub trait HasBbox {
39    /// Return a reference to the bounding box.
40    fn bbox(&self) -> &BoundingBox;
41}
42
43impl HasBbox for CatchmentUnit {
44    fn bbox(&self) -> &BoundingBox {
45        catchment::CatchmentUnit::bbox(self)
46    }
47}
48
49/// Trait for types identified by a [`UnitId`].
50///
51/// Enables generic operations over catchments, graph rows, and snap targets.
52pub trait HasUnitId {
53    /// Return the unit identifier.
54    fn unit_id(&self) -> UnitId;
55}
56
57impl HasUnitId for CatchmentUnit {
58    fn unit_id(&self) -> UnitId {
59        self.id()
60    }
61}
62
63impl HasUnitId for AdjacencyRow {
64    fn unit_id(&self) -> UnitId {
65        self.id()
66    }
67}
68
69impl HasUnitId for SnapTarget {
70    fn unit_id(&self) -> UnitId {
71        self.unit_id()
72    }
73}