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
impl H5Dataset
Sourcepub fn total_elements(&self) -> usize
pub fn total_elements(&self) -> usize
Return the total number of elements in the dataset.
Sourcepub fn element_size(&self) -> usize
pub fn element_size(&self) -> usize
Return the size of one element in bytes.
Sourcepub fn chunk_dims(&self) -> Option<Vec<usize>>
pub fn chunk_dims(&self) -> Option<Vec<usize>>
Return the chunk dimensions, if this is a chunked dataset.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Return whether this is a chunked dataset.
Sourcepub fn attr_names(&self) -> Result<Vec<String>>
pub fn attr_names(&self) -> Result<Vec<String>>
Return the names of all attributes on this dataset (read mode only).
Sourcepub fn attr(&self, attr_name: &str) -> Result<H5Attribute>
pub fn attr(&self, attr_name: &str) -> Result<H5Attribute>
Open an attribute by name (read mode only).
Sourcepub fn new_attr<T: 'static>(&self) -> AttrBuilder<'_, T>
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();Sourcepub fn write_raw<T: H5Type>(&self, data: &[T]) -> Result<()>
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.
Sourcepub fn write_chunk(&self, chunk_idx: usize, data: &[u8]) -> Result<()>
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.
Sourcepub fn write_chunks_batch(&self, chunks: &[(usize, &[u8])]) -> Result<()>
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.
Sourcepub fn extend(&self, new_dims: &[usize]) -> Result<()>
pub fn extend(&self, new_dims: &[usize]) -> Result<()>
Extend the dimensions of a chunked dataset.
Sourcepub fn read_slice<T: H5Type>(
&self,
starts: &[usize],
counts: &[usize],
) -> Result<Vec<T>>
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.
Sourcepub fn write_slice<T: H5Type>(
&self,
starts: &[usize],
counts: &[usize],
data: &[T],
) -> Result<()>
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.
Sourcepub fn read_vlen_strings(&self) -> Result<Vec<String>>
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.
Sourcepub fn read_raw<T: H5Type>(&self) -> Result<Vec<T>>
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().