Skip to main content

H5Dataset

Struct H5Dataset 

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

A handle to an HDF5 dataset, supporting typed read and write operations.

The dataset holds a shared reference to the file’s I/O backend, so it remains valid even if the originating H5File is moved or dropped (they share ownership via Rc).

Implementations§

Source§

impl H5Dataset

Source

pub fn shape(&self) -> Vec<usize>

Return the dataset dimensions.

Source

pub fn ndims(&self) -> usize

Return the number of dimensions (rank) of the dataset.

Source

pub fn total_elements(&self) -> usize

Return the total number of elements in the dataset.

Source

pub fn element_size(&self) -> usize

Return the size of one element in bytes.

Source

pub fn chunk_dims(&self) -> Option<Vec<usize>>

Return the chunk dimensions, if this is a chunked dataset.

Source

pub fn is_chunked(&self) -> bool

Return whether this is a chunked dataset.

Source

pub fn attr_names(&self) -> Result<Vec<String>>

Return the names of all attributes on this dataset (read mode only).

Source

pub fn attr(&self, attr_name: &str) -> Result<H5Attribute>

Open an attribute by name (read mode only).

Source

pub fn new_attr<T: 'static>(&self) -> AttrBuilder<'_, T>

Start building a new attribute on this dataset.

Returns a fluent builder. Call .shape(()) for a scalar attribute and .create("name") to finalize.

§Example
let file = H5File::create("attr.h5").unwrap();
let ds = file.new_dataset::<f32>().shape(&[10]).create("data").unwrap();
let attr = ds.new_attr::<VarLenUnicode>().shape(()).create("units").unwrap();
attr.write_scalar(&VarLenUnicode("meters".to_string())).unwrap();
Source

pub fn write_raw<T: H5Type>(&self, data: &[T]) -> Result<()>

Write a typed slice to the dataset (contiguous datasets only).

The slice length must match the total number of elements declared by the dataset shape. The data is reinterpreted as raw bytes and written to the file.

§Errors

Returns an error if:

  • The file is in read mode.
  • The data length does not match the declared shape.
Source

pub fn write_chunk(&self, chunk_idx: usize, data: &[u8]) -> Result<()>

Write a single chunk to a chunked dataset.

chunk_idx is the linear chunk index (typically the frame number for streaming datasets). data is the raw byte data for one chunk.

Source

pub fn write_chunks_batch(&self, chunks: &[(usize, &[u8])]) -> Result<()>

Write multiple chunks in a batch, optionally compressing in parallel.

chunks is a slice of (chunk_index, raw_data) pairs. When a filter pipeline is configured and the parallel feature is enabled, all chunks are compressed concurrently via rayon.

Source

pub fn extend(&self, new_dims: &[usize]) -> Result<()>

Extend the dimensions of a chunked dataset.

Source

pub fn flush(&self) -> Result<()>

Flush a chunked dataset’s index structures to disk.

Source

pub fn read_slice<T: H5Type>( &self, starts: &[usize], counts: &[usize], ) -> Result<Vec<T>>

Read a slice (hyperslab) of the dataset as a typed vector.

starts and counts define the N-dimensional selection: starts[d] = first index along dim d, counts[d] = how many elements.

Source

pub fn write_slice<T: H5Type>( &self, starts: &[usize], counts: &[usize], data: &[T], ) -> Result<()>

Write a typed slice to a sub-region of a contiguous dataset.

starts and counts define the N-dimensional selection.

Source

pub fn read_vlen_strings(&self) -> Result<Vec<String>>

Read variable-length strings from a dataset.

This handles h5py-style vlen string datasets that store strings as global heap references. Returns one String per element.

Source

pub fn read_raw<T: H5Type>(&self) -> Result<Vec<T>>

Read the entire dataset as a typed vector.

The raw bytes are read from the file and reinterpreted as T. The caller must ensure that T matches the datatype used when the dataset was written.

§Errors

Returns an error if:

  • The file is in write mode.
  • The raw data size is not a multiple of T::element_size().

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.