Skip to content

Serde integration#34

Merged
bmatthieu3 merged 10 commits intocds-astro:masterfrom
RReverser:serde
Aug 18, 2025
Merged

Serde integration#34
bmatthieu3 merged 10 commits intocds-astro:masterfrom
RReverser:serde

Conversation

@RReverser
Copy link
Copy Markdown
Contributor

Inspired by similar integration in rust-fitsio, I've implemented Serde integration for FITS headers and individual values.

This allows to parse arbitrary types instead of doing manual casts everywhere, as well as declaratively describe complex structures. For most notable demo, see the amount of removed code in wcs.rs - WCSParams already derives Deserialize, so now that we implement Deserializer, it's pretty trivial to connect the two.

For custom field extractions, I've also wrapped HashMap<String, Value> into a new ValueMap type which encapsulates IndexMap<String, Value> (to get consistent iteration order, something that didn't work correctly before) as well as all the previously existing helper methods that don't need the whole Header.


for i in 1..=z_naxis {
let naxisn = if let Ok(value) = values.get_parsed::<i64>(&format!("ZNAXIS{i}")) {
let naxisn = if let Ok(value) = values.check_for_naxisi(i) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had to restore that line which made the parsing of compressed tile images failing but otherwise everything worked well and this is very a nice feature. I also learned things thank you. This reduces the number of cast of card values in many aspects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, my bad - didn't notice it was NAXIS vs ZNAXIS. Thanks for catching it and glad you like the feature itself :)

@bmatthieu3 bmatthieu3 merged commit ac277c9 into cds-astro:master Aug 18, 2025
1 check passed
@RReverser
Copy link
Copy Markdown
Contributor Author

Btw, I was thinking that it would be great to add Serde support to bintables / asciitables - with deserialize_struct you even get a list of fields user is interested in from Serde, so you get a more natural integration for select_fields as well.

It's a much bigger task than implementing Serde for headers like I did here though, and I won't have much time for it at the moment. Just thought I'd mention in case it's something you're interested in looking into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants