Skip to main content

H5File

Struct H5File 

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

An HDF5 file opened for reading or writing.

Datasets created from this file hold a shared reference to the underlying I/O handle, so the file does not need to outlive its datasets (they share ownership via reference counting).

Implementations§

Source§

impl H5File

Source

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

Create a new HDF5 file at path. Truncates if the file already exists.

Source

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

Open an existing HDF5 file for reading.

Source

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

Open an existing HDF5 file for appending new datasets.

Existing datasets are preserved. New datasets can be added and will be written after the current end of file. Existing chunked datasets can be extended with write_chunk and extend_dataset.

use rust_hdf5::H5File;
let file = H5File::open_rw("existing.h5").unwrap();
let ds = file.new_dataset::<f64>().shape(&[100]).create("new_data").unwrap();
ds.write_raw(&vec![0.0f64; 100]).unwrap();
file.close().unwrap();
Source

pub fn root_group(&self) -> H5Group

Return a handle to the root group.

The root group can be used to create datasets and sub-groups.

Source

pub fn create_group(&self, name: &str) -> Result<H5Group>

Create a group in the root of the file.

use rust_hdf5::H5File;
let file = H5File::create("groups.h5").unwrap();
let grp = file.create_group("detector").unwrap();
Source

pub fn new_dataset<T: H5Type>(&self) -> DatasetBuilder<T>

Start building a new dataset with the given element type.

This returns a fluent builder. Call .shape(...) to set dimensions and .create("name") to finalize.

let file = H5File::create("build.h5").unwrap();
let ds = file.new_dataset::<f64>().shape(&[3, 4]).create("matrix").unwrap();
Source

pub fn set_attr_string(&self, name: &str, value: &str) -> Result<()>

Add a string attribute to the file (root group).

Source

pub fn set_attr_numeric<T: H5Type>(&self, name: &str, value: &T) -> Result<()>

Add a numeric attribute to the file (root group).

Source

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

Return the names of file-level (root group) attributes.

Source

pub fn attr_string(&self, name: &str) -> Result<String>

Read a file-level string attribute.

Source

pub fn is_writable(&self) -> bool

Check if the file is in write/append mode.

Source

pub fn write_vlen_strings(&self, name: &str, strings: &[&str]) -> Result<()>

Create a variable-length string dataset and write data.

This is a convenience method for writing h5py-compatible vlen string datasets using global heap storage.

Source

pub fn dataset(&self, name: &str) -> Result<H5Dataset>

Open an existing dataset by name (read mode).

Source

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

Return the names of all datasets in the root group.

Works in both read and write mode: in write mode, returns the names of datasets created so far; in read mode, returns the names discovered during file open.

Source

pub fn close(self) -> Result<()>

Explicitly close the file. For a writer, this finalizes the file (writes superblock, headers, etc.). For a reader, this is a no-op.

The file is also auto-finalized on drop, but calling close() lets you handle errors.

Source

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

Flush the file to disk. Only meaningful in write mode.

Auto Trait Implementations§

§

impl Freeze for H5File

§

impl !RefUnwindSafe for H5File

§

impl !Send for H5File

§

impl !Sync for H5File

§

impl Unpin for H5File

§

impl UnsafeUnpin for H5File

§

impl !UnwindSafe for H5File

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.