Skip to main content

Source

Trait Source 

Source
pub trait Source: Sealed {
    // Required methods
    fn size(&self) -> u64;
    fn slice<'a>(
        &'a mut self,
        offset: u64,
        len: usize,
        scratch: &'a mut Vec<u8>,
    ) -> Result<&'a [u8]>;
    fn read_owned(&mut self, offset: u64, len: usize) -> Result<Vec<u8>>;
}
Expand description

A seekable byte source the reader fetches HDU header and data units from. Sealed — implemented only by this crate’s source types, never externally.

Required Methods§

Source

fn size(&self) -> u64

Total byte length of the source. Fixed for the source’s lifetime and used to reject ranges that run past the end before allocating for them.

Source

fn slice<'a>( &'a mut self, offset: u64, len: usize, scratch: &'a mut Vec<u8>, ) -> Result<&'a [u8]>

The len bytes at offset, borrowed. In-memory sources return a slice of themselves (zero-copy); a streaming source reads into scratch and returns a slice of that. Errors if the range runs past the source.

Source

fn read_owned(&mut self, offset: u64, len: usize) -> Result<Vec<u8>>

The len bytes at offset in a fresh owned buffer — used where the bytes must outlive the read (the parsed table / ASCII-table backing store). Kept distinct from slice().to_vec() so a streaming source reads straight into the owned buffer (one copy) instead of staging through scratch first (two).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Source for MmapSource

Available on crate feature mmap only.
Source§

impl Source for SliceSource<'_>

Source§

impl<R: Read + Seek> Source for StreamSource<R>