Skip to content

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

Open
@AlanRace

Description

@AlanRace

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions