Expand description
§fits-header
A pure-Rust, MSVC-safe library for reading and writing the header of a FITS file.
It reads a header unit into an ordered Header of records, retaining every card so untouched
cards serialize byte-for-byte and only created or modified cards are re-rendered. Access is
strict and keyword-oriented: Header::get and friends take a Key that is either a bare
name (unique-or-FitsError::AmbiguousKeyword) or (name, occurrence). Values read through a
generic FromCard and write through IntoValue; batch edits are atomic; long strings use
the CONTINUE convention.
use fits_header::{Header, StructuralHints};
let mut h = Header::new();
h.set("OBJECT", "M31").unwrap();
h.set("EXPTIME", 120.0).unwrap();
assert_eq!(h.get::<f64>("EXPTIME").unwrap(), Some(120.0));
let bytes = h.to_bytes(&StructuralHints::default()).unwrap();
assert_eq!(bytes.len() % fits_header::BLOCK_LEN, 0);§Design
- Pure Rust, no C or system libraries; builds with the MSVC toolchain.
- An untouched card (and untouched long-string run) re-emits identical bytes.
- Ambiguous keyword access errors instead of guessing.
§Features
serde(off) — deriveSerialize/Deserializeon the public types.coords(off) — sexagesimal RA/Dec and MJD↔calendar helpers.
Structs§
- Fixed
- Write a float with a fixed number of decimal places.
- Header
- An ordered FITS header unit: records in appearance order, with strict keyword access and CRUD.
- Literal
- Write a literal token verbatim (numeric text a vendor supplied, or a value you don’t want reformatted).
- Record
- One header card. Carries its parsed content plus, when parsed and unmodified, the original bytes of its physical card(s) so it can be serialized verbatim.
- Sci
- Write a float in scientific notation with
Nsignificant digits (uppercaseE). - Structural
Hints - Image geometry used only when
Header::to_bytesmust synthesize missing structural cards.
Enums§
- Fits
Error - Errors from validated header mutations, ambiguous lookups, and oversized standalone serialization.
- Key
- Selects a record by keyword.
- Record
Kind - The semantic content of a record.
- Value
- A value card’s payload.
Constants§
- BLOCK_
LEN - Bytes per FITS block (36 cards).
- CARD_
LEN - Bytes per header card.
- MAX_
ZERO_ FILL - Largest data segment
Header::to_byteswill zero-fill, in bytes (1 GiB).
Traits§
- From
Card - Convert a record’s value into a Rust type. The extension point behind
Header::get. - Into
Value - Convert a Rust value into a
Value. The extension point behindHeader::set/append.
Functions§
- datetime_
to_ mjd - Convert a calendar date/time to a Modified Julian Date.
- deg_
to_ sexagesimal_ dec - Format degrees as a sexagesimal declination
±DD MM SS.ss(sign preserved). - deg_
to_ sexagesimal_ ra - Format degrees as a sexagesimal right ascension
HH MM SS.sss(re-parses to the input within millisecond-of-arc precision). - format_
datetime - Format a date/time back to the FITS civil form (
YYYY-MM-DDThh:mm:ss[.fff]), dropping a zero sub-second part. - mjd_
to_ datetime - Convert a Modified Julian Date to a calendar date/time.
- parse
- Parse one FITS header unit from raw bytes.
- parse_
datetime - Parse a FITS civil date/time (
YYYY-MM-DD[Thh:mm:ss[.fff]]), timezone-naive. - parse_
f64 - Parse a float, accepting the Fortran
Dexponent (1.5D3). - parse_
i64 - Parse an integer, accepting decimal-form integers (
"20.0"→20). - sexagesimal_
dec_ to_ deg - Parse a sexagesimal declination (
±D M S) to degrees. The sign is taken from the leading token, so it is preserved even when the degrees field is0(-00 30 00→-0.5). Requires thecoordsfeature. - sexagesimal_
ra_ to_ deg - Parse a sexagesimal right ascension (
H M S, space- or colon-separated, optional fractional seconds) to degrees (hours × 15). Requires thecoordsfeature.