### Install and Use fitssummary CLI Source: https://docs.rs/fitsio/latest/src/fitsio/lib Instructions on how to install the `fitssummary` command-line tool using cargo and an example of its usage to print FITS file summaries. ```sh $ fitssummary ../testdata/full_example.fits ``` -------------------------------- ### Fitssummary Command Line Tool Source: https://docs.rs/fitsio/latest/index Provides an example of using the `fitssummary` command-line tool, installed via `cargo install`, to display summaries of FITS files. It shows the file path, mode, and details about each HDU. ```bash $ fitssummary ../testdata/full_example.fits file: ../testdata/full_example.fits mode: READONLY extnum hdutype hduname details 0 IMAGE_HDU dimensions: [100, 100], type: Long 1 BINARY_TBL TESTEXT num_cols: 4, num_rows: 50 ``` -------------------------------- ### Create and Open FITS File Example Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile This example demonstrates how to create a new FITS file using the `fitsio` crate. It utilizes the `tempfile` crate to create a temporary directory and then constructs a FITS file within it. The `FitsFile::create` method is used to initialize the file, followed by `open` to finalize its creation. ```rust # let tdir = tempfile::Builder::new().prefix("fitsio-").tempdir().unwrap(); # let tdir_path = tdir.path(); # let _filename = tdir_path.join("test.fits"); # let filename = _filename.to_str().unwrap(); use fitsio::FitsFile; // let filename = ...; let fptr = FitsFile::create(filename).open().unwrap(); ``` -------------------------------- ### Rust Standard Library and Tools Source: https://docs.rs/fitsio/latest/fitsio/index References to key Rust documentation resources, including the official Rust website, The Book, the Standard Library API Reference, Rust by Example, the Cargo Guide, and Clippy documentation. These are essential for developers working with Rust projects. ```rust Rust Resources: Rust Website: https://www.rust-lang.org/ The Book: https://doc.rust-lang.org/book/ Standard Library API Reference: https://doc.rust-lang.org/std/ Rust by Example: https://doc.rust-lang.org/rust-by-example/ Cargo Guide: https://doc.rust-lang.org/cargo/guide/ Clippy Documentation: https://doc.rust-lang.org/nightly/clippy ``` -------------------------------- ### Fitssummary Command Line Tool Source: https://docs.rs/fitsio/latest/fitsio A command-line utility installed via `cargo install` that prints summaries of FITS files to standard output. It takes FITS file paths as arguments. ```bash $ fitssummary ../testdata/full_example.fits file: ../testdata/full_example.fits mode: READONLY extnum hdutype hduname details 0 IMAGE_HDU dimensions: [100, 100], type: Long 1 BINARY_TBL TESTEXT num_cols: 4, num_rows: 50 ``` -------------------------------- ### Fitssummary Command Line Tool Source: https://docs.rs/fitsio/latest/fitsio/index Installs and uses the `fitssummary` command-line tool to display summaries of FITS files. This tool provides details about the file mode and its HDUs. ```bash $ fitssummary ../testdata/full_example.fits file: ../testdata/full_example.fits mode: READONLY extnum hdutype hduname details 0 IMAGE_HDU dimensions: [100, 100], type: Long 1 BINARY_TBL TESTEXT num_cols: 4, num_rows: 50 ``` -------------------------------- ### Create FITS File with Data Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Demonstrates the creation of a new FITS file using a temporary file path and preparing data to be written. This is a setup step for subsequent write operations. ```rust with_temp_file(|filename| { let data_to_write: Vec = (0..100).map(|v| v + 50).collect(); let mut f = FitsFile::create(filename).open().unwrap(); // ... further operations would follow here ``` -------------------------------- ### Python Example for Creating FITS Files with ndarrays Source: https://docs.rs/fitsio/latest/src/fitsio/ndarray_compat This section provides Python code examples using astropy.io.fits and numpy to create FITS files containing multi-dimensional arrays. These examples are used to generate test data for the fitsio crate's ndarray compatibility. ```python // Creation of data in Python: // >>> import numpy as np // >>> from astropy.io import fits // >>> nums = np.arange(36) // >>> image = nums.reshape(6,6) // >>> cube = nums.reshape(2,3,6) // >>> hyper = nums.reshape(2,3,3,2) // >>> fits.writeto("image.fits", image) // >>> fits.writeto("cube.fits", cube) // >>> fits.writeto("hyper.fits", hyper) ``` -------------------------------- ### Open FITS File Example Source: https://docs.rs/fitsio/latest/src/fitsio/lib Demonstrates how to open a FITS file in read-only mode using the `fitsio` library. It shows the necessary unsafe block for raw pointer manipulation and the conversion to a `FitsFile` struct. ```rust let mut fptr = std::ptr::null_mut(); let c_filename = std::ffi::CString::new("../testdata/full_example.fits").unwrap(); let mut status = 0; unsafe { fitsio::fits_open_file(&mut fptr, c_filename.as_ptr(), 0, &mut status) }; assert_eq!(status, 0); let mut f = unsafe { fitsio::FitsFile::from_raw(fptr, fitsio::FileOpenMode::READONLY) }.unwrap(); ``` -------------------------------- ### Rustdoc Keyboard Shortcuts Source: https://docs.rs/fitsio/latest/help Provides a list of keyboard shortcuts for navigating and interacting with rustdoc generated documentation. These shortcuts enhance the efficiency of browsing API references and code examples. ```APIDOC `?`: Show this help dialog `S` / `/`: Focus the search field `↑`: Move up in search results `↓`: Move down in search results `←` / `→`: Switch result tab (when results focused) `⏎`: Go to active search result `+`: Expand all sections `-`: Collapse all sections ``` -------------------------------- ### Threadsafe Access Example Source: https://docs.rs/fitsio/latest/index Demonstrates how to obtain a threadsafe wrapper for FitsFile and use it across multiple threads. It shows cloning the threadsafe file, spawning threads, locking the mutex, and accessing HDUs. ```rust let f = fptr.threadsafe(); /* Spawn loads of threads... */ for i in 0..100 { let mut f1 = f.clone(); /* Send the cloned ThreadsafeFitsFile to another thread */ let handle = thread::spawn(move || { /* Get the underlyng fits file back */ let mut t = f1.lock().unwrap(); /* Fetch a different HDU per thread */ let hdu_num = i % 2; let _hdu = t.hdu(hdu_num).unwrap(); }); } ``` -------------------------------- ### Threadsafe Access Example Source: https://docs.rs/fitsio/latest/fitsio Demonstrates how to obtain a threadsafe wrapper for FitsFile and use it across multiple threads. It shows cloning the threadsafe file, spawning threads, locking the mutex, and accessing HDUs. ```rust let f = fptr.threadsafe(); /* Spawn loads of threads... */ for i in 0..100 { let mut f1 = f.clone(); /* Send the cloned ThreadsafeFitsFile to another thread */ let handle = thread::spawn(move || { /* Get the underlyng fits file back */ let mut t = f1.lock().unwrap(); /* Fetch a different HDU per thread */ let hdu_num = i % 2; let _hdu = t.hdu(hdu_num).unwrap(); }); } ``` -------------------------------- ### Read Header Key Example Source: https://docs.rs/fitsio/latest/src/fitsio/hdu Demonstrates how to read a specific header key from a FITS HDU. The example shows the setup for reading a key, implying that the `read_key` method is available on `FitsHdu` and takes the `FitsFile` and the key name as arguments. ```rust # fn main() -> Result<(), Box> { # let filename = "../testdata/full_example.fits"; // Example of reading a header key // let hdu = FitsHdu::new(&mut fits_file, 0)?; // Assuming fits_file is initialized // let key_value = hdu.read_key(&mut fits_file, "KEYNAME")?; # Ok(()) # } ``` -------------------------------- ### Create and Write FITS File Headers Source: https://docs.rs/fitsio/latest/src/fitsio/lib Demonstrates creating a new FITS file, writing integer and string key-value pairs to the header, and reading them back. It also shows how to write and read keys with associated comments. ```rust # fn try_main() -> Result<(), Box> { # let tdir = tempfile::Builder::new().prefix("fitsio-").tempdir().unwrap(); # let tdir_path = tdir.path(); # let filename = tdir_path.join("test.fits"); # { # let mut fptr = fitsio::FitsFile::create(filename).open()?; # fptr.hdu(0)?.write_key(&mut fptr, "foo", 1i64)?; # assert_eq!(fptr.hdu(0)?.read_key::(&mut fptr, "foo")?, 1i64); # # // with comments # use fitsio::HeaderValue; # fptr.hdu(0)?.write_key(&mut fptr, "bar", (1i64, "bar comment"))?; # # let HeaderValue { value, comment } = fptr.hdu(0)?.read_key::>(&mut fptr, "bar")?; # assert_eq!(value, 1i64); # assert_eq!(comment, Some("bar comment".to_string())); # Ok(()) # } # } # fn main() { try_main().unwrap(); } ``` -------------------------------- ### Get HDU Names Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Retrieves a list of names for all HDUs within a FITS file. This example asserts that the expected HDU names are returned. ```rust let hdu_names = f.hdu_names().unwrap(); assert_eq!(hdu_names.as_slice(), &["", "TESTEXT"]); ``` -------------------------------- ### Test 2D Array Reading Source: https://docs.rs/fitsio/latest/src/fitsio/ndarray_compat This test case is intended to verify the reading of a 2D array from a FITS file. It follows the setup described in the Python examples for creating test data. ```rust #[test] fn test_2d_array() { ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/hdu/index Provides an overview of the fitsio crate, its purpose, and its dependencies. It highlights the MIT and Apache-2.0 licenses and links to the source code and crates.io page. ```rust /// Project: /websites/rs_fitsio /// Content: /// [ Docs.rs ](https://docs.rs/) /// * [ fitsio-0.21.7 ](https://docs.rs/fitsio/latest/fitsio/hdu/index.html "Rust implmentation of astronomy fits file handling") /// * fitsio 0.21.7 /// * [](https://docs.rs/fitsio/0.21.7/fitsio/hdu/index.html "Get a link to this specific version") /// * [ ](https://docs.rs/crate/fitsio/latest "See fitsio in docs.rs") /// * [MIT](https://spdx.org/licenses/MIT)/[Apache-2.0](https://spdx.org/licenses/Apache-2.0) /// * Links /// * [ ](https://github.com/simonrw/rust-fitsio) /// * [ ](https://github.com/simonrw/rust-fitsio) /// * [ ](https://crates.io/crates/fitsio "See fitsio in crates.io") /// * [ ](https://docs.rs/crate/fitsio/latest/source/ "Browse source of fitsio-0.21.7") /// * Owners /// * [ ](https://crates.io/users/cjordan) /// * [ ](https://crates.io/users/simonrw) /// * Dependencies /// * * [ fitsio-sys ^0.5 _normal_ ](https://docs.rs/fitsio-sys/^0.5) /// * [ libc ^0.2.44 _normal_ ](https://docs.rs/libc/^0.2.44) /// * [ ndarray ^0.16.0 _normal_ _optional_ ](https://docs.rs/ndarray/^0.16.0) /// * [ criterion ^0.5.1 _dev_ ](https://docs.rs/criterion/^0.5.1) /// * [ fitsio-derive ^0.2 _dev_ ](https://docs.rs/fitsio-derive/^0.2) /// * [ proc-macro2 ^1.0.80 _dev_ ](https://docs.rs/proc-macro2/^1.0.80) /// * [ serde ^1.0.178 _dev_ ](https://docs.rs/serde/^1.0.178) /// * [ tempfile ^3.0.0 _dev_ ](https://docs.rs/tempfile/^3.0.0) /// * [ version-sync ^0.9.0 _dev_ ](https://docs.rs/version-sync/^0.9.0) /// * Versions /// * [ **100%** of the crate is documented ](https://docs.rs/crate/fitsio/latest) /// * [ Platform ](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) /// * [x86_64-unknown-linux-gnu](https://docs.rs/crate/fitsio/latest/target-redirect/x86_64-unknown-linux-gnu/fitsio/hdu/index.html) /// * [ Feature flags ](https://docs.rs/fitsio/latest/features "Browse available feature flags of fitsio-0.21.7") /// /// /// * [docs.rs](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) /// * [](https://docs.rs/about) /// * [](https://docs.rs/about/badges) /// * [](https://docs.rs/about/builds) /// * [](https://docs.rs/about/metadata) /// * [](https://docs.rs/about/redirections) /// * [](https://docs.rs/about/download) /// * [](https://docs.rs/about/rustdoc-json) /// * [](https://docs.rs/releases/queue) /// * [](https://foundation.rust-lang.org/policies/privacy-policy/#docs.rs) /// /// /// * [Rust](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) /// * [Rust website](https://www.rust-lang.org/) /// * [The Book](https://doc.rust-lang.org/book/) /// * [Standard Library API Reference](https://doc.rust-lang.org/std/) /// * [Rust by Example](https://doc.rust-lang.org/rust-by-example/) /// * [The Cargo Guide](https://doc.rust-lang.org/cargo/guide/) /// * [Clippy Documentation](https://doc.rust-lang.org/nightly/clippy) /// /// ## [Module hdu](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) ## [fitsio](https://docs.rs/fitsio/latest/fitsio/index.html)0.21.7 ## [Module hdu](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) ### [Module Items](https://docs.rs/fitsio/latest/fitsio/hdu/index.html#structs) * [Structs](https://docs.rs/fitsio/latest/fitsio/hdu/index.html#structs "Structs") * [Enums](https://docs.rs/fitsio/latest/fitsio/hdu/index.html#enums "Enums") * [Traits](https://docs.rs/fitsio/latest/fitsio/hdu/index.html#traits "Traits") ## [In crate fitsio](https://docs.rs/fitsio/latest/fitsio/index.html) ### [Modules](https://docs.rs/fitsio/latest/fitsio/index.html#modules) * [errors](https://docs.rs/fitsio/latest/fitsio/errors/index.html) * [hdu](https://docs.rs/fitsio/latest/fitsio/hdu/index.html) * [headers](https://docs.rs/fitsio/latest/fitsio/headers/index.html) * [images](https://docs.rs/fitsio/latest/fitsio/images/index.html) * [tables](https://docs.rs/fitsio/latest/fitsio/tables/index.html) * [threadsafe_fitsfile](https://docs.rs/fitsio/latest/fitsio/threadsafe_fitsfile/index.html) ### [Structs](https://docs.rs/fitsio/latest/fitsio/index.html#structs) * [CfitsioVersion](https://docs.rs/fitsio/latest/fitsio/struct.CfitsioVersion.html) * [FitsFile](https://docs.rs/fitsio/latest/fitsio/struct.FitsFile.html) ### [Enums](https://docs.rs/fitsio/latest/fitsio/index.html#enums) * [FileOpenMode](https://docs.rs/fitsio/latest/fitsio/enum.FileOpenMode.html) ### [Functions](https://docs.rs/fitsio/latest/fitsio/index.html#functions) * [cfitsio_version](https://docs.rs/fitsio/latest/fitsio/fn.cfitsio_version.html) [](https://docs.rs/fitsio/latest/fitsio/all.html "show sidebar") [fitsio](https://docs.rs/fitsio/latest/fitsio/index.html) # Module hduCopy item path [Settings](https://docs.rs/fitsio/latest/settings.html) [Help](https://docs.rs/fitsio/latest/help.html) Summary[Source](https://docs.rs/fitsio/latest/src/fitsio/hdu.rs.html#1-1137) Expand description Fits HDU related code ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/macros Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust crate: fitsio version: 0.21.7 license: MIT/Apache-2.0 source: https://github.com/simonrw/rust-fitsio dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) documentation: 100% covered ``` -------------------------------- ### Get Current HDU Object Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Retrieves the current HDU as a FitsHdu object. This involves first getting the number of the current HDU and then fetching the HDU object itself. ```rust pub(crate) fn current_hdu(&mut self) -> Result { let current_hdu_number = self.hdu_number(); self.hdu(current_hdu_number) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/headers/index Provides an overview of the fitsio crate, its version, license, source code links, dependencies, and documentation status. ```rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% documented ``` -------------------------------- ### Get Number of HDUs Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Calculates and returns the total number of Header Data Units (HDUs) present in the FITS file. It interacts with the underlying FITS library to get this count. ```rust fn num_hdus(&mut self) -> Result { let mut status = 0; let mut num_hdus = 0; unsafe { fits_get_num_hdus(self.fptr.as_mut() as *mut _, &mut num_hdus, &mut status); } check_status(status).map(|_| num_hdus as _) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/images Overview of the fitsio crate, including its version, license, source code links, and dependencies. It highlights the crate's purpose in handling FITS files in Rust. ```Rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% complete ``` -------------------------------- ### Clone Implementation Example for HeaderValue Source: https://docs.rs/fitsio/latest/src/fitsio/headers/header_value Provides an example of how to create and use a `HeaderValue` instance, demonstrating its basic structure and initialization. This snippet is part of the documentation for the `Clone` implementation. ```rust # use fitsio::headers::HeaderValue; let mut hv = HeaderValue { value: 1u16, comment: None, }; ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/lib Provides a comprehensive overview of the fitsio crate, including its version, license, source code links, and dependencies. It also highlights the documentation status and supported platforms. ```rust crate: fitsio version: 0.21.7 license: MIT/Apache-2.0 dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) documentation: 100% platforms: - x86_64-unknown-linux-gnu ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/images/index Provides an overview of the fitsio crate, its version, license, dependencies, and links to source code and related resources. ```rust Crate: fitsio Version: 0.21.7 License: MIT/Apache-2.0 Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% documented Source: https://github.com/simonrw/rust-fitsio Crates.io: https://crates.io/crates/fitsio ``` -------------------------------- ### Rust Result Unwrap Panic Example Source: https://docs.rs/fitsio/latest/fitsio/errors/type Illustrates the panic behavior of `unwrap()` when called on an `Err` variant of a Rust Result. This example shows how `unwrap()` will panic with the error message. ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### Read Rows from HDU Source: https://docs.rs/fitsio/latest/src/fitsio/hdu Reads a specified number of rows from a FITS HDU, starting from a given row index. This function is also generic and relies on the `ReadImage` trait for data type handling. It takes a mutable `FitsFile` reference, the starting row index, and the total number of rows to read. ```rust pub fn read_rows( &self, fits_file: &mut FitsFile, start_row: usize, num_rows: usize, ) -> Result { fits_file.make_current(self)?; T::read_rows(fits_file, self, start_row, num_rows) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/all Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It also lists available platform targets and feature flags. ```rust Crate: fitsio-0.21.7 License: MIT/Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) Platforms: - x86_64-unknown-linux-gnu Features: - All documented (100%) ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Provides an overview of the fitsio crate, including its purpose, version, license, dependencies, and documentation status. It also links to the source code and related resources. ```Rust crate: fitsio ^0.21.7 License: MIT / Apache-2.0 Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% documented Source: https://github.com/simonrw/rust-fitsio Crates.io: https://crates.io/crates/fitsio Docs.rs: https://docs.rs/fitsio/latest ``` -------------------------------- ### Rust Result is_err Example Source: https://docs.rs/fitsio/latest/fitsio/errors/type Illustrates the is_err method for checking if a Result is Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/stringutils Overview of the fitsio crate, including its purpose, license, and links to external resources like GitHub and crates.io. It also lists the crate's dependencies and development dependencies. ```Rust Project: /websites/rs_fitsio Dependencies: * fitsio-sys ^0.5 * libc ^0.2.44 * ndarray ^0.16.0 (optional) Dev Dependencies: * criterion ^0.5.1 * fitsio-derive ^0.2 * proc-macro2 ^1.0.80 * serde ^1.0.178 * tempfile ^3.0.0 * version-sync ^0.9.0 License: MIT/Apache-2.0 Links: * Docs.rs: https://docs.rs/fitsio/latest/src/fitsio/stringutils.rs.html * GitHub: https://github.com/simonrw/rust-fitsio * Crates.io: https://crates.io/crates/fitsio ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/headers/mod Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage. ```rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) Documentation Coverage: 100% ``` -------------------------------- ### Rust Result is_ok Example Source: https://docs.rs/fitsio/latest/fitsio/errors/type Shows how to use the is_ok method to check if a Result is Ok. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/tables/enum Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It also highlights the documentation status and supported platforms. ```rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Documentation: https://docs.rs/fitsio/latest/fitsio/ Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation Coverage: 100% Platforms: - x86_64-unknown-linux-gnu ``` -------------------------------- ### Generic Any Trait Implementation Source: https://docs.rs/fitsio/latest/fitsio/hdu/enum Demonstrates the blanket implementation of the Any trait for any type T, providing a way to get the TypeId of an instance. ```APIDOC impl Any for T where T: 'static + ?Sized type_id(&self) -> TypeId Gets the `TypeId` of `self`. [Read more](https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id) ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/headers/header_value Provides an overview of the fitsio Rust crate, including its version, license, source code links, and dependencies. It also highlights the documentation status and available platform targets. ```Rust Crate: fitsio-0.21.7 License: MIT/Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% complete Platforms: - x86_64-unknown-linux-gnu ``` -------------------------------- ### Rust Result Transpose Example Source: https://docs.rs/fitsio/latest/fitsio/errors/type Demonstrates the transpose method for Result, E> and Option>. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### Get HDU Names Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Retrieves a vector of strings, where each string is the name of an HDU in the FITS file. It iterates through all HDUs to collect their names. ```rust pub(crate) fn hdu_names(&mut self) -> Result> { let num_hdus = self.num_hdus()?; let mut result = Vec::with_capacity(num_hdus); for i in 0..num_hdus { let hdu = self.hdu(i)?; let name = hdu.name(self)?; result.push(name); } Ok(result) } ``` -------------------------------- ### Create and Resize 3D Image Source: https://docs.rs/fitsio/latest/src/fitsio/images Demonstrates creating a FITS file with a 3D image, resizing it, and verifying the new dimensions. This involves creating the file, adding an image, resizing it, and then reopening the file to check the updated image shape. ```rust #[test] fn test_resize_3d() { with_temp_file(|filename| { // Scope ensures file is closed properly { let mut f = FitsFile::create(filename).open().unwrap(); let image_description = ImageDescription { data_type: ImageType::Long, dimensions: &[100, 20], }; f.create_image("foo".to_string(), &image_description) .unwrap(); } /* Now resize the image */ { let mut f = FitsFile::edit(filename).unwrap(); let hdu = f.hdu("foo").unwrap(); hdu.resize(&mut f, &[1024, 1024, 5]).unwrap(); } /* Images are only resized when flushed to disk, so close the file and * open it again */ { let mut f = FitsFile::edit(filename).unwrap(); let hdu = f.hdu("foo").unwrap(); match hdu.info { HduInfo::ImageInfo { shape, .. } => { assert_eq!(shape, [1024, 1024, 5]); } _ => panic!("Unexpected hdu type"), } } }); } ``` -------------------------------- ### Get File Path Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Returns a reference to the file path associated with the FitsFile object. This indicates the location of the FITS file on the filesystem. ```rust pub fn file_path(&self) -> &Path { &self.file_path } ``` -------------------------------- ### Open FITS File Source: https://docs.rs/fitsio/latest/src/fitsio/lib Demonstrates how to open an existing FITS file using the `FitsFile::open` method. This is the primary entry point for interacting with FITS files in the library. ```rust use fitsio::FitsFile; use std::error::Error; fn try_main() -> Result<(), Box> { let filename = "../testdata/full_example.fits"; let mut f = FitsFile::open(filename)?; // Further operations on the FITS file can be performed here Ok(()) } ``` -------------------------------- ### Get Primary HDU Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Retrieves the primary Header Data Unit (HDU) from the FITS file. This is typically the first HDU in the file. ```rust pub fn primary_hdu(&mut self) -> Result { self.hdu(0) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/threadsafe_fitsfile Provides an overview of the fitsio crate, its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```rust Crate: fitsio-0.21.7 License: MIT/Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) Documentation Coverage: 100% ``` -------------------------------- ### Get Key Information Source: https://docs.rs/fitsio/latest/src/fitsio/longnam Retrieves information about a FITS keyword. This function is unsafe and requires careful handling of pointers. ```rust pub(crate) unsafe fn fits_get_key_info( fptr: *mut fitsfile, keyname: *const c_char, value: *mut c_char, comm: *mut c_char, status: *mut c_int, ) -> c_int { ffgky(fptr, keyname, value, comm, status) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/tables Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust Crate: fitsio-0.21.7 License: MIT/Apache-2.0 Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation Coverage: 100% Source: https://github.com/simonrw/rust-fitsio Crates.io: https://crates.io/crates/fitsio ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/errors Provides an overview of the fitsio Rust crate, including its version, license, dependencies, and links to external resources like source code repositories and documentation. ```rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Repository: https://github.com/simonrw/rust-fitsio Documentation: https://docs.rs/fitsio/latest Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) Dev Dependencies: - criterion ^0.5.1 - fitsio-derive ^0.2 - proc-macro2 ^1.0.80 - serde ^1.0.178 - tempfile ^3.0.0 - version-sync ^0.9.0 Documentation Coverage: 100% ``` -------------------------------- ### Get File Path Source: https://docs.rs/fitsio/latest/fitsio/fitsfile/struct Shows how to retrieve the file path associated with a `FitsFile` object using the `file_path` method. ```rust // Assuming fptr is an initialized FitsFile object let path = fptr.file_path(); println!("File path: {:?}", path); ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/errors/index Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. It highlights the crate's purpose as a Rust implementation for astronomy FITS file handling. ```rust Crate: fitsio Version: 0.21.7 License: MIT / Apache-2.0 Description: Rust implementation of astronomy FITS file handling Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) Source: https://github.com/simonrw/rust-fitsio Documentation: https://docs.rs/fitsio/latest/fitsio/ ``` -------------------------------- ### Rust Result is_ok_and Example Source: https://docs.rs/fitsio/latest/fitsio/errors/type Demonstrates using is_ok_and with a predicate to check if a Result is Ok and its value matches a condition. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Open and Copy FITS File HDU Source: https://docs.rs/fitsio/latest/src/fitsio/lib Demonstrates opening an existing FITS file, creating a temporary directory, creating a new FITS file, and copying an HDU from the source to the destination file. ```rust let filename = "../testdata/full_example.fits"; let mut src_fptr = fitsio::FitsFile::open(filename)?; let tdir = tempfile::Builder::new().prefix("fitsio-").tempdir().unwrap(); let tdir_path = tdir.path(); let filename = tdir_path.join("test.fits"); let mut dest_fptr = fitsio::FitsFile::create(filename).open()?; let hdu = src_fptr.hdu(1)?; hdu.copy_to(&mut src_fptr, &mut dest_fptr)?; Ok(()) ``` -------------------------------- ### Fitsio Threadsafe Access Source: https://docs.rs/fitsio/latest/fitsio/index Discusses how to achieve thread-safe access to FITS files using the fitsio crate, with an example provided. ```rust // Example of threadsafe access in fitsio // Refer to https://docs.rs/fitsio/latest/fitsio/index.html#threadsafe-access ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/fitsio/tables/index Provides an overview of the fitsio crate, its purpose, and its modules. Includes links to source code, dependencies, and related crates. ```rust // Crate: fitsio // Version: 0.21.7 // Description: Rust implementation of astronomy fits file handling // License: MIT/Apache-2.0 // Repository: https://github.com/simonrw/rust-fitsio // Crates.io: https://crates.io/crates/fitsio // Modules: // - errors: Handles errors related to FITS file operations. // - hdu: Deals with Header Data Units (HDUs) in FITS files. // - headers: Provides functionality for reading and writing FITS headers. // - images: Supports handling of image data within FITS files. // - tables: Manages tabular data in FITS files. // - threadsafe_fitsfile: Offers thread-safe access to FITS files. // Structs: // - CfitsioVersion: Represents the version of the underlying CFITSIO library. // - FitsFile: Represents an opened FITS file. // Enums: // - FileOpenMode: Specifies the mode in which a FITS file can be opened (e.g., read, write). // Functions: // - cfitsio_version: Retrieves the version of the CFITSIO library. ``` -------------------------------- ### Get Current HDU Number Source: https://docs.rs/fitsio/latest/src/fitsio/fitsfile Returns the index (0-based) of the currently active HDU in the FITS file. This is determined by querying the FITS library. ```rust pub(crate) fn hdu_number(&mut self) -> usize { let mut hdu_num = 0; unsafe { fits_get_hdu_num(self.fptr.as_mut() as *mut _, &mut hdu_num); } (hdu_num - 1) as usize } ``` -------------------------------- ### Get Number of Columns Source: https://docs.rs/fitsio/latest/src/fitsio/longnam Retrieves the number of columns in a FITS HDU. This function is unsafe and requires careful handling of pointers. ```rust pub(crate) unsafe fn fits_get_num_cols( fptr: *mut fitsfile, ncols: *mut c_int, status: *mut c_int, ) -> c_int { ffgncl(fptr, ncols, status) } ``` -------------------------------- ### fitsio Crate Overview Source: https://docs.rs/fitsio/latest/src/fitsio/longnam Provides an overview of the fitsio crate, including its version, license, source code links, and dependencies. This information is useful for understanding the project's ecosystem and integration. ```Rust Crate: fitsio-0.21.7 License: MIT/Apache-2.0 Source: https://github.com/simonrw/rust-fitsio Dependencies: - fitsio-sys ^0.5 - libc ^0.2.44 - ndarray ^0.16.0 (optional) - criterion ^0.5.1 (dev) - fitsio-derive ^0.2 (dev) - proc-macro2 ^1.0.80 (dev) - serde ^1.0.178 (dev) - tempfile ^3.0.0 (dev) - version-sync ^0.9.0 (dev) Documentation: 100% complete ```