forked from aldanor/hdf5-rust
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
I'm not sure if this is an issue or expected behavior, but I'm surprised that this doesn't cause an error.
If I have a dataset with an enum type, and attempt to read it as a different enum, reading succeeds but results in incorrect values.
Concretely:
use hdf5_metno::{File, H5Type};
use ndarray::Ix1;
#[derive(H5Type, Debug)]
#[repr(u8)]
#[allow(dead_code)]
enum First {
A = 0,
B = 1,
C = 2,
}
#[derive(H5Type, Debug)]
#[repr(u8)]
enum Second {
A = 0,
B = 1,
C = 2,
D = 3,
E = 4,
}
fn main() -> anyhow::Result<()> {
let file = File::create("test.h5")?;
let to_write = [Second::A, Second::B, Second::C, Second::D, Second::E];
let dataset = file.new_dataset::<Second>().shape([5]).create("second")?;
dataset.write(&to_write)?;
file.close()?;
let file = File::open("test.h5")?;
let dataset = file.dataset("second")?;
let data_in_as_second = dataset.read::<Second, Ix1>()?;
println!("data read as `Second`: {:?}", data_in_as_second);
let data_in_as_first = dataset.read::<First, Ix1>()?;
println!("data read as `First`: {:?}", data_in_as_first);
Ok(())
}Outputs:
data read as `Second`: [A, B, C, D, E], shape=[5], strides=[1], layout=CFcf (0xf), const ndim=1
data read as `First`: [A, B, C, A, A], shape=[5], strides=[1], layout=CFcf (0xf), const ndim=1
Cargo.toml
[package]
name = "hdf5_enums"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.100"
hdf5-metno = "0.11.0"
ndarray = "0.17.1"Should read return an error in this kind of situation?
Metadata
Metadata
Assignees
Labels
No labels