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
impl FitsHeader
Sourcepub fn from_bytes(raw: Vec<u8>) -> FitsHeader
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());Sourcepub fn to_bytes(self) -> Vec<u8> ⓘ
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);Sourcepub fn get_card<K: PartialEq<FitsHeaderKeyword>>(
&mut self,
keyword: K,
) -> Option<&mut FitsHeaderCard>
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());Sourcepub fn set_card<K: PartialEq<FitsHeaderKeyword> + Into<FitsHeaderKeyword>, T: FitsHeaderValue + 'static>(
&mut self,
keyword: K,
value: T,
comment: Option<String>,
) -> Result<(), FitsHeaderError>
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")));Sourcepub fn set_value<K, T: FitsHeaderValue + 'static>(
&mut self,
keyword: K,
value: T,
) -> Result<(), FitsHeaderError>
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))
);Sourcepub fn set_comment<K: PartialEq<FitsHeaderKeyword>>(
&mut self,
keyword: K,
comment: Option<String>,
) -> Result<(), FitsHeaderError>
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
impl Clone for FitsHeader
Source§fn clone(&self) -> FitsHeader
fn clone(&self) -> FitsHeader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FitsHeader
impl Debug for FitsHeader
Source§impl Default for FitsHeader
impl Default for FitsHeader
Source§fn default() -> FitsHeader
fn default() -> FitsHeader
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for FitsHeader
impl !RefUnwindSafe for FitsHeader
impl !Send for FitsHeader
impl !Sync for FitsHeader
impl Unpin for FitsHeader
impl !UnwindSafe for FitsHeader
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.