FitsHeader

Struct FitsHeader 

Source
pub struct FitsHeader {
    pub cards: Vec<FitsHeaderCard>,
}
Available on crate feature fits only.
Expand description

The header portion of an HDU.

Fields§

§cards: Vec<FitsHeaderCard>

The card images contained in the header.

Implementations§

Source§

impl FitsHeader

Source

pub fn new() -> Self

Constructs an empty header.

Source

pub fn from_bytes(raw: Vec<u8>) -> FitsHeader

Constructs a FitsHeader from the given bytes.

§Examples
use astro_rs::fits::*;
use std::rc::Rc;

// default primary HDU header bytes
let bytes = *b"SIMPLE  =                    T                                                  BITPIX  =                    8                                                  NAXIS   =                    0                                                  END                                                                             ";
let mut header = FitsHeader::from_bytes(bytes.to_vec());

assert!(*header
    .get_card(SIMPLE_KEYWORD)
    .and_then(|card| card.get_value::<bool>().ok())
    .unwrap_or_default());
assert_eq!(
    header
        .get_card(BITPIX_KEYWORD)
        .and_then(|card| card.get_value::<Bitpix>().ok()),
    Some(Rc::new(Bitpix::U8))
);
assert_eq!(
    header
        .get_card(NAXIS_KEYWORD)
        .and_then(|card| card.get_value::<u16>().ok()),
    Some(Rc::new(0))
);
assert!(header.get_card(END_KEYWORD).is_some());
Source

pub fn to_bytes(self) -> Vec<u8>

Serializes the header into bytes.

§Examples
use astro_rs::fits::*;

let hdu = primary_hdu::default();
let mut bytes = b"SIMPLE  =                    T                                                  BITPIX  =                    8                                                  NAXIS   =                    0                                                  END                                                                             ".to_vec();
bytes.resize(2880, b' ');

assert_eq!(hdu.header.to_bytes(), bytes);
Source

pub fn get_card<K: PartialEq<FitsHeaderKeyword>>( &mut self, keyword: K, ) -> Option<&mut FitsHeaderCard>

Searches the header cards for a match with the given keyword.

§Examples
use astro_rs::fits::*;

let mut hdu = primary_hdu::default();
assert!(hdu.header.get_card(SIMPLE_KEYWORD).is_some());
assert!(hdu.header.get_card(EXTNAME_KEYWORD).is_none());
Source

pub fn set_card<K: PartialEq<FitsHeaderKeyword> + Into<FitsHeaderKeyword>, T: FitsHeaderValue + 'static>( &mut self, keyword: K, value: T, comment: Option<String>, ) -> Result<(), FitsHeaderError>

Sets the value and comment of the card with the given keyword. If a card already exists, the data is overwritten. If a card does not exist, one is created.

§Examples
use astro_rs::fits::*;
use std::rc::Rc;

let mut header = FitsHeader::new();
header.set_card(SIMPLE_KEYWORD, true, None);
assert!(*header
    .get_card(SIMPLE_KEYWORD)
    .and_then(|card| card.get_value::<bool>().ok())
    .unwrap_or_default());

header.set_card(SIMPLE_KEYWORD, false, Some(String::from("FITS STANDARD")));
let mut card = header.get_card(SIMPLE_KEYWORD).unwrap();
assert!(!*card.get_value::<bool>()?);
assert_eq!(card.get_comment()?, Rc::new(String::from("FITS STANDARD")));
Source

pub fn set_value<K, T: FitsHeaderValue + 'static>( &mut self, keyword: K, value: T, ) -> Result<(), FitsHeaderError>

Sets the value of the card with the given keyword. If a card already exists, the value is overwritten, and the comment is retained. If a card does not exist, one is created.

§Examples
use astro_rs::fits::*;
use std::rc::Rc;

let bytes = *b"SIMPLE  =                    T / FITS STANDARD                                  ";
let mut header = FitsHeader::from_bytes(bytes.to_vec());
header.set_value(SIMPLE_KEYWORD, false)?;
let mut card = header.get_card(SIMPLE_KEYWORD).unwrap();
assert!(!*card.get_value::<bool>()?);
assert_eq!(card.get_comment()?, Rc::new(String::from("FITS STANDARD")));

header.set_value(BITPIX_KEYWORD, Bitpix::U8)?;
assert_eq!(
    header
        .get_card(BITPIX_KEYWORD)
        .and_then(|card| card.get_value::<Bitpix>().ok()),
    Some(Rc::new(Bitpix::U8))
);
Source

pub fn set_comment<K: PartialEq<FitsHeaderKeyword>>( &mut self, keyword: K, comment: Option<String>, ) -> Result<(), FitsHeaderError>

Sets the comment of the card with the given keyword. If a card already exists, the comment is overwritten, and the value is retained. If a card does not exist, this function has no effect.

§Examples
use astro_rs::fits::*;
use std::rc::Rc;

let mut hdu = primary_hdu::default();
hdu.header.set_comment(SIMPLE_KEYWORD, Some(String::from("FITS STANDARD")));
let mut card = hdu.header.get_card(SIMPLE_KEYWORD).unwrap();
assert!(*card.get_value::<bool>()?);
assert_eq!(card.get_comment()?, Rc::new(String::from("FITS STANDARD")));

hdu.header.set_comment(EXTNAME_KEYWORD, Some(String::from("Error 404")));
assert!(hdu.header.get_card(EXTNAME_KEYWORD).is_none());

Trait Implementations§

Source§

impl Clone for FitsHeader

Source§

fn clone(&self) -> FitsHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FitsHeader

Source§

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

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

impl Default for FitsHeader

Source§

fn default() -> FitsHeader

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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