-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathattribute.rs
More file actions
30 lines (27 loc) · 1.12 KB
/
attribute.rs
File metadata and controls
30 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! This module implements the traits to extend the hdf5 [Attribute] type to provide robust, conventient helper methods.
use super::{
AttributeExt,
error::{ConvertResult, NexusHDF5Result},
};
use crate::run_engine::NexusDateTime;
use hdf5::{Attribute, types::VarLenUnicode};
impl AttributeExt for Attribute {
/// Maybe this should be a provided method?
#[tracing::instrument(skip_all, level = "trace", err(level = "warn"))]
fn get_datetime(&self) -> NexusHDF5Result<NexusDateTime> {
let string: VarLenUnicode = self.read_scalar().err_attribute(self)?;
string.parse().err_attribute(self)
}
#[tracing::instrument(skip_all, level = "trace", err(level = "warn"))]
fn set_string(&self, value: &str) -> NexusHDF5Result<()> {
self.write_scalar(&value.parse::<VarLenUnicode>().err_attribute(self)?)
.err_attribute(self)
}
#[tracing::instrument(skip_all, level = "trace", err(level = "warn"))]
fn get_string(&self) -> NexusHDF5Result<String> {
Ok(self
.read_scalar::<VarLenUnicode>()
.err_attribute(self)?
.to_string())
}
}