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;

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));

// The header block only — creating a file means appending your own pixel data after
// this; editing an existing file means Header::update_file, which preserves it.
let bytes = h.to_header_bytes();
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.

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 (via Key) 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 RecordKind 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).

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.

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§

format_datetime
Format a date/time back to the FITS civil form (YYYY-MM-DDThh:mm:ss[.fff]), dropping a zero sub-second part.
parseDeprecated
Deprecated free-function alias for Header::parse; use that instead.
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).

Type Aliases§

Result
A Result whose error is always FitsError.