fits-header
A pure-Rust library for reading and writing the header of a FITS file.
- Pure Rust, no C or system libraries. Builds with the MSVC toolchain.
- Every card is retained on parse; untouched cards (including long-string runs) re-serialize byte-for-byte. Only created or edited cards are re-rendered.
- Keyword access is strict: a bare name addresses the sole occurrence of a keyword and
errors when it is duplicated;
("NAME", n)selects the n-th occurrence. - Create, read, update, and delete single or multiple keywords; batch mutations are atomic (all or nothing).
- Typed reads and writes:
get::<T>covers strings, numbers, booleans, and date/times;Literal/Fixed/Sciwrappers control number formatting on write. - Long strings use the
CONTINUEconvention on read and write (withLONGSTRN). - The API is an ordered header of
(keyword, value, comment)cards; it contains no application types.
Usage
use ;
Serialization outputs
to_header_bytes()— the header block only (cards +END, padded to a 2880-byte multiple). The primary path when editing a real file: splice it onto the file's data.to_bytes(&hints)— a standalone FITS object. MissingSIMPLE/BITPIX/NAXIS*cards are synthesized from the hints, and the declared data segment is zero-filled. Data larger thanMAX_ZERO_FILL(1 GiB) returnsFitsError::DataTooLargeinstead of allocating.
Documentation
API documentation is generated from the crate's rustdoc and published at
docs.rs/fits-header. Every public item is documented;
the examples are compiled and run as part of the test suite. Build the docs locally
with cargo doc --no-deps --all-features --open.
Features
serde(off by default) — deriveSerialize/DeserializeonHeader,Record,Value, andStructuralHints.coords(off by default) — astronomy helpers: sexagesimal RA/Dec parsing and formatting, MJD ↔ calendar conversion. No extra dependencies.
Development
License
Licensed under the Apache License, Version 2.0.