Expand description
Pure Rust HDF5 library with full read/write support.
This crate provides a high-level API for creating and reading HDF5 files without any C dependencies. It supports contiguous and chunked datasets, deflate compression (with optional shuffle), SWMR streaming, and hyperslab (slice) I/O.
§Quick start
§Writing a dataset
use rust_hdf5::H5File;
let file = H5File::create("output.h5").unwrap();
let ds = file.new_dataset::<f64>()
.shape(&[100, 200])
.create("matrix")
.unwrap();
let data: Vec<f64> = (0..20_000).map(|i| i as f64).collect();
ds.write_raw(&data).unwrap();
file.close().unwrap();§Reading a dataset
use rust_hdf5::H5File;
let file = H5File::open("output.h5").unwrap();
let ds = file.dataset("matrix").unwrap();
let data = ds.read_raw::<f64>().unwrap();
assert_eq!(data.len(), 20_000);§Chunked + compressed streaming
use rust_hdf5::H5File;
let file = H5File::create("stream.h5").unwrap();
let ds = file.new_dataset::<f32>()
.shape(&[0usize, 64])
.chunk(&[1, 64])
.max_shape(&[None, Some(64)])
.deflate(6)
.create("sensor")
.unwrap();
for frame in 0..1000u64 {
let vals: Vec<f32> = (0..64).map(|i| (frame * 64 + i) as f32).collect();
let raw: Vec<u8> = vals.iter().flat_map(|v| v.to_le_bytes()).collect();
ds.write_chunk(frame as usize, &raw).unwrap();
}
ds.extend(&[1000, 64]).unwrap();
file.close().unwrap();§Hyperslab (slice) I/O
use rust_hdf5::H5File;
// Write a sub-region
let file = H5File::create("slice.h5").unwrap();
let ds = file.new_dataset::<i32>()
.shape(&[10usize, 10])
.create("grid")
.unwrap();
ds.write_raw(&[0i32; 100]).unwrap();
ds.write_slice(&[2, 3], &[3, 4], &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]).unwrap();
file.close().unwrap();
// Read a sub-region
let file = H5File::open("slice.h5").unwrap();
let ds = file.dataset("grid").unwrap();
let region = ds.read_slice::<i32>(&[2, 3], &[3, 4]).unwrap();
assert_eq!(region.len(), 12);Re-exports§
pub use attribute::H5Attribute;pub use dataset::H5Dataset;pub use error::Hdf5Error;pub use error::Result;pub use file::H5File;pub use group::H5Group;pub use types::Complex32;pub use types::Complex64;pub use types::CompoundType;pub use types::H5Type;pub use types::HBool;pub use types::VarLenUnicode;
Modules§
- attribute
- Attribute support.
- dataset
- Dataset creation and I/O.
- error
- Error types for the hdf5 public API crate.
- file
- HDF5 file handle — the main entry point for the public API.
- format
- Pure Rust HDF5 on-disk format codec.
- group
- Group support.
- swmr
- Single Writer / Multiple Reader (SWMR) API.
- types
- Mapping from Rust types to HDF5 datatype messages.