Skip to content

Commit

Permalink
Include function to get cfitsio version
Browse files Browse the repository at this point in the history
Note: currently only works on cfitsio >= v4.0.0 since versions previous
to this don't include the `CFITSIO_MICRO` symbol used in this function.

TODO: update this
  • Loading branch information
simonrw committed Dec 31, 2024
1 parent f306c58 commit ceb199a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fitsio-sys/examples/print_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use fitsio_sys::cfitsio_version;

fn main() {
println!("cfitsio version: {}", cfitsio_version());
}
26 changes: 26 additions & 0 deletions fitsio-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,29 @@ mod sys {
}

pub use sys::*;

// global functions

/// Representation of the version of cfitsio used within bindings
pub struct CfitsioVersion {
/// Patch version
pub patch: u32,
/// Minor version
pub minor: u32,
/// Major version
pub major: u32,
}

impl std::fmt::Display for CfitsioVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}

pub fn cfitsio_version() -> CfitsioVersion {
CfitsioVersion {
patch: CFITSIO_MICRO,
minor: CFITSIO_MINOR,
major: CFITSIO_MAJOR,
}
}
3 changes: 3 additions & 0 deletions fitsio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,9 @@ let _hdu = t.hdu(hdu_num).unwrap();

pub use fitsio_sys as sys;

// re-export version information
pub use sys::{cfitsio_version, CfitsioVersion};

#[macro_use]
mod macros;
mod fitsfile;
Expand Down

0 comments on commit ceb199a

Please sign in to comment.