Skip to main content

Crate fits_header

Crate fits_header 

Source
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) — derive Serialize/Deserialize on 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 N significant digits (uppercase E).
StructuralHints
Image geometry used only when Header::to_bytes must synthesize missing structural cards.

Enums§

FitsError
Errors from validated header mutations, ambiguous lookups, and oversized standalone serialization.
Key
Selects a record by keyword.
RecordKind
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_bytes will zero-fill, in bytes (1 GiB).

Traits§

FromCard
Convert a record’s value into a Rust type. The extension point behind Header::get.
IntoValue
Convert a Rust value into a Value. The extension point behind Header::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 D exponent (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 is 0 (-00 30 00-0.5). Requires the coords feature.
sexagesimal_ra_to_deg
Parse a sexagesimal right ascension (H M S, space- or colon-separated, optional fractional seconds) to degrees (hours × 15). Requires the coords feature.