Skip to main content

H5Attribute

Struct H5Attribute 

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

A handle to an HDF5 attribute.

After creating an attribute via AttrBuilder::create, use write_scalar or write_string to set its value.

In read mode, use read_string to read string attributes.

Implementations§

Source§

impl H5Attribute

Source

pub fn name(&self) -> &str

Return the attribute name.

Source

pub fn write_scalar(&self, value: &VarLenUnicode) -> Result<()>

Write a scalar value to the attribute.

For VarLenUnicode, this writes a fixed-length string attribute whose size is determined by the string value.

Source

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

Write a string value to the attribute (convenience method).

Source

pub fn write_numeric<T: H5Type>(&self, value: &T) -> Result<()>

Write a numeric scalar attribute.

let file = H5File::create("num_attr.h5").unwrap();
let ds = file.new_dataset::<f32>().shape(&[10]).create("data").unwrap();
ds.write_raw(&[0.0f32; 10]).unwrap();
let attr = ds.new_attr::<f64>().shape(()).create("scale").unwrap();
attr.write_numeric(&3.14f64).unwrap();
Source

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

Read a numeric scalar attribute.

let file = H5File::open("num_attr.h5").unwrap();
let ds = file.dataset("data").unwrap();
let attr = ds.attr("scale").unwrap();
let val: f64 = attr.read_numeric().unwrap();
Source

pub fn read_string(&self) -> Result<String>

Read the attribute value as a string.

Works for fixed-length string attributes (as written by this library) and returns the string value with any trailing null bytes stripped.

Source

pub fn read_raw(&self) -> Result<Vec<u8>>

Read the raw attribute data bytes.

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.