HduList

Struct HduList 

Source
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>

Source

pub fn new(reader: BufReader<R>) -> Self

Constructs an empty HduList.

Source

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

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

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

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())
Source

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

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

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

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§

Source§

impl<R: Debug> Debug for HduList<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HduList<Cursor<Vec<u8>>>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RealAny for T
where T: Any,

Source§

fn real_type_id(&self) -> TypeId

Available on crate feature fits only.
Gets the base type ID for self.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more