zhl16
zhl16 is a small #![no_std] Rust crate for core Bühlmann ZHL-16 tissue loading primitives.
The crate currently provides:
- 16-compartment nitrogen and helium tissue loading.
- ZHL-16C tissue constants loaded from
data/zhl16c.csvat compile time. - Gas mixture handling for oxygen, helium, and derived nitrogen fractions.
- Maximum operating pressure and equivalent narcotic pressure helpers.
- Per-compartment safe ambient pressure calculation from a gradient factor.
- Lightweight unit wrappers for pressure, time, pressure rate, and frequency.
This is not a complete dive computer. It does not currently provide dive profile planning, ascent scheduling, decompression stop generation, CNS/OTU tracking, gas switching, validation against dive-computer reference profiles, or safety policy around user input.
Installation
Add the crate to your Cargo.toml:
[]
= "0.1"
Example
use ;
let mut body = new;
let trimix_10_20 = new.expect;
body.evolve
.expect;
let first_compartment = &body.compartments;
let n2 = first_compartment
.get_nitrogen_pressure
.to;
let he = first_compartment
.get_helium_pressure
.to;
let safe_pressure = first_compartment
.safe_ambient_pressure
.expect
.to;
assert!;
assert!;
let _ = safe_pressure;
Gas Mixtures
GasMixture::new(oxygen_fraction, helium_fraction) stores oxygen and helium fractions. Nitrogen is derived as:
1.0 - oxygen_fraction - helium_fraction
The constructor returns Result<GasMixture, GasMixtureError> if either supplied fraction is not finite, oxygen is zero, either fraction is negative, or oxygen plus helium is greater than 1.0.
use ;
Tissue Constants
The ZHL-16-C constants live in data/zhl16c.csv. A build script validates that file and generates the Rust TISSUE_CONSTANTS array at compile time.
This keeps the runtime crate no_std; the CSV parsing happens only during compilation.
Units
The crate uses simple typed quantity wrappers:
PressureTimePressureRateFrequency
Each quantity stores a base-unit f64 internally and converts through unit enums such as PressureUnit::Bar and TimeUnit::Seconds.
Public quantity constructors return Result<_, QuantityError> and reject NaN values.
Safety
Do not use this crate as the sole basis for real dive planning or life-support decisions. The API is still early and intentionally exposes low-level model primitives rather than a validated decompression algorithm.
License
Licensed under MIT license