Skip to main content

SwmrFileReader

Struct SwmrFileReader 

Source
pub struct SwmrFileReader { /* private fields */ }
Expand description

SWMR reader for monitoring a streaming HDF5 file.

Opens a file being written by a concurrent SwmrFileWriter and periodically calls refresh to pick up new data.

use rust_hdf5::swmr::SwmrFileReader;

let mut reader = SwmrFileReader::open("stream.h5").unwrap();

loop {
    reader.refresh().unwrap();
    let names = reader.dataset_names();
    if let Some(shape) = reader.dataset_shape("frames").ok() {
        println!("frames shape: {:?}", shape);
        if shape[0] > 0 {
            let data = reader.read_dataset_raw("frames").unwrap();
            println!("got {} bytes", data.len());
            break;
        }
    }
    std::thread::sleep(std::time::Duration::from_millis(100));
}

Implementations§

Source§

impl SwmrFileReader

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an HDF5 file for SWMR reading.

Source

pub fn refresh(&mut self) -> Result<()>

Re-read the superblock and dataset metadata from disk.

Call this periodically to pick up new data written by the concurrent SWMR writer.

Source

pub fn dataset_names(&self) -> Vec<String>

Return the names of all datasets.

Source

pub fn dataset_shape(&self, name: &str) -> Result<Vec<u64>>

Return the current shape of a dataset.

Source

pub fn read_dataset_raw(&mut self, name: &str) -> Result<Vec<u8>>

Read the raw bytes of a dataset.

Source

pub fn read_dataset<T: H5Type>(&mut self, name: &str) -> Result<Vec<T>>

Read a dataset as a typed vector.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.