Expand description
Optional online data sources with an on-disk cache and an explicit offline mode: weather, soundings, elevation, ThrustCurve and motor stock.
Guide: Online data and the cache says what works today and what is planned.
Status: pre-alpha, with six data sources: open_meteo, a launch site’s weather as a
sounding (M5.2a, the first weather increment; the weather page explains
it); wyoming, weather-balloon soundings from the University of Wyoming’s archive
(M5.2b; the soundings page); nomads, NOAA’s GFS and RAP
forecasts as GRIB2 cuts from NOMADS (M5.2c; the NOAA forecasts page);
elevation, a site’s ground height from Open-Meteo (M5.3b; the
elevation page); motor_finder, motor stock and prices from
motor.fusionspace.co (M5.4a; the motor stock page); and
thrustcurve, motor records and thrust curves from ThrustCurve.org, matched to the motors in
stock (M5.4b; the same page), and on_demand, one motor found there by name for
a simulator that lacks its curve (M4.5b). This
crate does network and file I/O, so it is never a dependency of the pure core. Milestone
M5.1 added the cache, the offline mode and HTTP: a Client asks a Transport for a URL’s bytes only when it is Mode::Online
and its Cache holds no fresh copy. In Mode::Offline it never calls the transport; it
answers from the cache, stale or not, and says which. The http feature adds Http, the
transport over HTTP and HTTPS (rustls, no OpenSSL), and Cache::platform_dir names the
platform’s usual cache folder.
use hpr_net::{Cache, Client, Freshness, Mode, NetError, Source, Transport};
/// A transport that answers every URL with the same bytes.
struct Canned;
impl Transport for Canned {
fn get(&self, _url: &str) -> Result<Vec<u8>, String> {
Ok(b"42".to_vec())
}
}
let dir = std::env::temp_dir().join(format!("hpr-net-doc-{}", std::process::id()));
let source = Source {
name: "Example".into(),
attribution: "Example data".into(),
ttl_s: 3600,
};
let url = "https://example.test/x";
let online = Client::new(Canned, Cache::new(&dir), Mode::Online);
assert_eq!(online.fetch(&source, url, 1_000)?.freshness, Freshness::Fetched);
let offline = Client::new(Canned, Cache::new(&dir), Mode::Offline);
let later = offline.fetch(&source, url, 1_000 + 7_200)?;
assert_eq!((later.freshness, later.body.as_slice()), (Freshness::Stale, &b"42"[..]));Modules§
- elevation
- A launch site’s elevation (height above sea level) from Open-Meteo’s elevation API.
- motor_
finder - Motor stock and prices from motor.fusionspace.co’s public API.
- nomads
- Weather from NOAA’s GFS and RAP forecasts: a small GRIB2 cut from NOMADS’ grib filter around a
launch site, turned into a
SoundingProfile. - on_
demand - One motor found by name on ThrustCurve.org, with the curve file to fly it by: for a simulator that lacks the motor’s curve (M4.5b, motors on demand; ADR-154, the decision on fetching them).
- open_
meteo - Weather from Open-Meteo: a launch site’s forecast (or a past day’s archived forecast) on
pressure levels, turned into a
SoundingProfile. - thrustcurve
- Motor records and thrust curves from ThrustCurve.org’s API, and the join that gives a motor in stock its curve.
- wyoming
- Weather-balloon soundings from the University of Wyoming’s radiosonde archive, turned into a
SoundingProfile.
Structs§
- Cache
- A directory of cached responses, keyed by URL.
- Cache
Entry - What the cache knows about one URL.
- Client
- A cache in front of a transport.
- Fetched
- A body and where it came from.
- Http
- A
Transportthat fetches over HTTP and HTTPS, behind the crate’shttpfeature. - Http
Config - How an
Httptransport behaves. Start fromHttpConfig::defaultand change fields. - Replay
- A transport that replays recorded responses from a directory, for tests and offline demos.
- Source
- One online data source: its name, the credit its terms ask for, and how long a copy stays fresh.
Enums§
- Freshness
- How a
Fetchedbody relates to its source. - Mode
- Whether the client may use the network.
- NetError
- Why a fetch failed.