Skip to main content

Crate rust_hdf5

Crate rust_hdf5 

Source
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::AttrShape;
pub use attribute::H5Attribute;
pub use dataset::AllocTime;
pub use dataset::ChunkIndex;
pub use dataset::DatasetAccess;
pub use dataset::FillTime;
pub use dataset::FillValue;
pub use dataset::H5Dataset;
pub use dataset::ReadNumeric;
pub use dataset::StorageLayout;
pub use dataset::VirtualView;
pub use error::Hdf5Error;
pub use error::Result;
pub use file::H5File;
pub use file::H5FileOptions;
pub use format::creation_order::CreationOrder;
pub use format::messages::datatype::ByteOrder;
pub use format::messages::datatype::DatatypeMessage;
pub use format::messages::filter::Filter;
pub use format::messages::filter::FilterPipeline;
pub use format::messages::superblock_ext::BtreeKMessage;
pub use format::messages::superblock_ext::DriverInfoMessage;
pub use format::messages::superblock_ext::FileSpaceInfoMessage;
pub use format::messages::superblock_ext::FileSpaceStrategy;
pub use format::messages::superblock_ext::SharedMessageTableMessage;
pub use format::messages::virtual_mapping::VirtualMapping;
pub use format::reference::Reference;
pub use format::selection::Hyperslab;
pub use format::selection::HyperslabBlock;
pub use format::selection::PointSelection;
pub use format::selection::RegularHyperslab;
pub use format::selection::Selection;
pub use format::storage_kind::AttributeStorage;
pub use format::storage_kind::LinkStorage;
pub use format::LibverBound;
pub use group::H5Group;
pub use named_datatype::H5NamedDatatype;
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.
named_datatype
Committed (named) datatypes.
swmr
Single Writer / Multiple Reader (SWMR) API.
types
Mapping from Rust types to HDF5 datatype messages.

Structs§

ExternalFileSegment
One resolved external-file slot (H5O_EFL_ID): the on-disk message stores each slot’s name as an offset into a local heap, so this is that slot after the heap lookup, in the order the dataset’s logical byte range concatenates them.
SuperblockExtension
Everything the superblock extension object header contributes to the file-level view.

Enums§

FileLocking
File-locking policy applied at file open time.
LinkClass
The class of one link record in a group: what H5Lget_info reports, carrying the value H5Lget_val returns for the classes that have one.
LockMode
Whether the file should be locked shared (multiple readers) or exclusive (sole owner).

Constants§

MAX_COMPACT_DATA
Bytes a compact dataset’s raw image may occupy.
MIN_USERBLOCK
Smallest userblock a file can be created with, and the granularity of every larger one: H5Pset_userblock takes 0 or a power of two from here up, because H5FD_locate_signature looks for the superblock at 0 and then at this offset doubled repeatedly.