pub struct HduList<R> { /* private fields */ }Available on crate feature
fits only.Expand description
A representation of the entirety of a FITS file.
Implementations§
Source§impl<R: Read> HduList<R>
impl<R: Read> HduList<R>
Sourcepub fn get_by_index(&mut self, index: usize) -> Option<&mut Hdu>
pub fn get_by_index(&mut self, index: usize) -> Option<&mut Hdu>
Retrieves the HDU at the given index, or None if an HDU doesn’t exist at the index.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
assert!(hdu_list.get_by_index(0).is_none());
hdu_list.push(primary_hdu::default());
assert!(hdu_list.get_by_index(0).is_some());Sourcepub fn get_by_name(&mut self, name: &str) -> Option<&mut Hdu>
pub fn get_by_name(&mut self, name: &str) -> Option<&mut Hdu>
Retrieves the HDU with the given value for the EXTNAME keyword, or None if an HDU
with the given name doesn’t exist.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
// empty list
assert!(hdu_list.get_by_name("hdu_name").is_none());
// name does not match
let mut img_hdu = image_hdu::default();
let name_card = FitsHeaderCard::from(*b"EXTNAME = 'name_of_hdu' ");
img_hdu.header.cards.insert(img_hdu.header.cards.len() - 1, name_card);
hdu_list.push(img_hdu);
assert!(hdu_list.get_by_name("hdu_name").is_none());
// name matches
let mut img_hdu = image_hdu::default();
let name_card = FitsHeaderCard::from(*b"EXTNAME = 'hdu_name' ");
img_hdu.header.cards.insert(img_hdu.header.cards.len() - 1, name_card);
hdu_list.push(img_hdu);
assert!(hdu_list.get_by_name("hdu_name").is_some());Sourcepub fn first_mut(&mut self) -> Option<&mut Hdu>
pub fn first_mut(&mut self) -> Option<&mut Hdu>
Returns a mutable pointer to the first HDU, or None if the list is empty.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
assert!(hdu_list.first_mut().is_none());
hdu_list.push(primary_hdu::default());
assert!(hdu_list.first_mut().is_some());Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Hdu>
pub fn iter_mut(&mut self) -> IterMut<'_, Hdu>
Deserializes all HDUs if necessary, then returns a mutable iterator over the HDUs.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
hdu_list.push(primary_hdu::default());
// find the primary HDU
assert!(hdu_list
.iter_mut()
.find_map(|hdu| if hdu.header.get_card(SIMPLE_KEYWORD).is_some() {
Some(hdu)
} else {
None
})
.is_some())Sourcepub fn insert(&mut self, index: usize, hdu: Hdu)
pub fn insert(&mut self, index: usize, hdu: Hdu)
Deserializes all HDUs up to index if necessary, then inserts the given hdu.
§Panics
Panics if index is out of bounds.
§Examples
ⓘ
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
// panics, index is out of bounds
hdu_list.insert(1, image_hdu::default());use astro_rs::fits::*;
let mut hdu_list = HduList::default();
hdu_list.push(primary_hdu::default());
hdu_list.insert(1, image_hdu::default());
assert_eq!(hdu_list.iter_mut().count(), 2);Sourcepub fn push(&mut self, hdu: Hdu)
pub fn push(&mut self, hdu: Hdu)
Appends hdu to the end of the HDU list.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
hdu_list.push(primary_hdu::default());
assert_eq!(hdu_list.iter_mut().count(), 1);
hdu_list.push(image_hdu::default());
assert_eq!(hdu_list.iter_mut().count(), 2);Sourcepub fn write<W: Write>(
&mut self,
writer: &mut BufWriter<W>,
) -> Result<(), Error>
pub fn write<W: Write>( &mut self, writer: &mut BufWriter<W>, ) -> Result<(), Error>
Writes the HDU list via the given writer.
§Examples
use astro_rs::fits::*;
use std::io::*;
let in_cursor = Cursor::new(SIMPLE_KEYWORD.to_vec());
let mut hdu_list = HduList::new(BufReader::new(in_cursor));
let out_cursor = Cursor::new(Vec::new());
let mut out_writer = BufWriter::new(out_cursor);
hdu_list.write(&mut out_writer)?;
assert_eq!(out_writer.get_ref().get_ref(), &SIMPLE_KEYWORD.to_vec());
Sourcepub fn is_header_valid(&mut self) -> Result<bool, FitsHeaderError>
pub fn is_header_valid(&mut self) -> Result<bool, FitsHeaderError>
Validates the existence and format of the SIMPLE header card.
§Examples
use astro_rs::fits::*;
let mut hdu_list = HduList::default();
// empty header
assert!(!hdu_list.is_header_valid()?);
let mut hdu = Hdu::new();
// non-empty header missing simple card
let bitpix_card = FitsHeaderCard::from(*b"BITPIX = -32 / FITS BITS/PIXEL ");
hdu.header.cards.insert(0, bitpix_card);
hdu_list.push(hdu);
assert!(!hdu_list.is_header_valid()?);
// valid header
let simple_card = FitsHeaderCard::from(*b"SIMPLE = T / FITS STANDARD ");
hdu_list.first_mut().unwrap().header.cards.insert(0, simple_card);
assert!(hdu_list.is_header_valid()?);Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for HduList<R>where
R: Freeze,
impl<R> !RefUnwindSafe for HduList<R>
impl<R> !Send for HduList<R>
impl<R> !Sync for HduList<R>
impl<R> Unpin for HduList<R>where
R: Unpin,
impl<R> !UnwindSafe for HduList<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> RealAny for Twhere
T: Any,
impl<T> RealAny for Twhere
T: Any,
Source§fn real_type_id(&self) -> TypeId
fn real_type_id(&self) -> TypeId
Available on crate feature
fits only.Gets the base type ID for
self.