Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T in VarLenArray<T> cannot contain another VarLenArray #222

Open
AlanRace opened this issue Jan 3, 2023 · 1 comment · May be fixed by #232
Open

T in VarLenArray<T> cannot contain another VarLenArray #222

AlanRace opened this issue Jan 3, 2023 · 1 comment · May be fixed by #232

Comments

@AlanRace
Copy link

AlanRace commented Jan 3, 2023

Hello,
I have a file where one dataset is stored as a VarLenArray of a custom compound which contains at least one VarLenArray. The following code does not work with the current version as the trait Copy is not implemented for VarLenArray

#[derive(H5Type, Copy, Debug)] // register with HDF5
#[repr(C)]
pub struct Cluster {
    id: i32,
    name: VarLenAscii,
    colour: i32,
    neighbours: VarLenArray<i32>,
}

fn read_clusters(dataset: Dataset) -> Result<()> {
    let clusters: VarLenArray<Cluster> = dataset.read_scalar()?;

    println!("{:?}", clusters);

    // ... process clusters ...

    Ok(())
}

Results in the error:

error[E0204]: the trait `Copy` may not be implemented for this type
  --> src\main.rs:60:18
   |
60 | #[derive(H5Type, Copy, Debug)] // register with HDF5
   |                  ^^^^
...
63 |     name: VarLenAscii,
   |     ----------------- this field does not implement `Copy`
...
67 |     neighbours: VarLenArray<i32>,
   |     -------------------------- this field does not implement `Copy`

If I change VarLenArray to requiring Clone instead of Copy then I can get this to compile, run and read in the correct data, but I am unsure what effects that has on the code. What would be a good solution to this problem?

@mulimoen
Copy link
Collaborator

mulimoen commented Jan 3, 2023

I would think it should be OK to lower from Copy to Clone. I would recommend creating a PR for this and see if CI complains ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants