Skip to main content

winds_engine/
lib.rs

1//! Deterministic wind fields and radiosonde validation for trajectory
2//! simulation, consumed by rockets-engine.
3//!
4//! Everything here is stateless and reproducible from inputs: no network, no
5//! wall clock, no unseeded randomness. The [`WindField`] trait, the profile
6//! types and the analytic profiles are this crate's own. They were the
7//! staging ground for the modeling core planned for ballistics-engine's
8//! `wind` module (see `docs/winds-engine-plan.md`), but ballistics-engine's
9//! wind fields (unreleased) differ: its `WindField::wind` takes and returns
10//! `nalgebra::Vector3<f64>`, with no counterpart to [`Wind`]; its
11//! `ConstantField` is a tuple struct over that vector; its `LogProfile` and
12//! `EkmanProfile` keep their fields private behind getters; and its
13//! constructors return `WindFieldError`. Moving this crate onto those types
14//! changes its public API (every [`WindField::wind`] call,
15//! [`validate::validate`]'s signature), so it is a deliberate breaking
16//! release, not a drop-in re-export.
17//!
18//! - [`field`]: the [`WindField`] trait, [`ConstantField`], [`ProfileField`].
19//! - [`analytic`]: [`LogProfile`](analytic::LogProfile) and
20//!   [`EkmanProfile`](analytic::EkmanProfile) boundary-layer models.
21//! - [`sounding`]: radiosonde interchange-format parsing.
22//! - [`validate`]: profile-vs-sounding comparison metrics.
23
24pub mod analytic;
25pub mod field;
26pub mod sounding;
27pub mod validate;
28
29pub use field::{ConstantField, ProfileField, ProfileLevel, Wind, WindField};
30pub use sounding::{Sounding, SoundingLevel};
31pub use validate::{LayerError, ValidationReport};
32
33/// Crate-wide error: invalid input with a field name and reason.
34#[derive(Debug, Clone, PartialEq)]
35pub struct Error {
36    /// The offending input or field.
37    pub field: &'static str,
38    /// Why it was rejected.
39    pub reason: String,
40}
41
42impl Error {
43    pub(crate) fn invalid(field: &'static str, reason: impl Into<String>) -> Self {
44        Self {
45            field,
46            reason: reason.into(),
47        }
48    }
49}
50
51impl std::fmt::Display for Error {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        write!(f, "{}: {}", self.field, self.reason)
54    }
55}
56
57impl std::error::Error for Error {}
58
59/// Crate-wide result.
60pub type Result<T> = std::result::Result<T, Error>;