message: Add an example to README
diff: @@ -9,6 +9,60 @@ Thread-safe Rust bindings and high-level wrappers for the HDF5 library API.
  Requires HDF5 library of version 1.8.4 or later.
  +## Example
  +
  +```rust
  +#[derive(h5::H5Type, Clone, PartialEq, Debug)]
  +#[repr(u8)]
  +pub enum Color {
  + RED = 1,
  + GREEN = 2,
  + BLUE = 3,
  +}
  +
  +#[derive(h5::H5Type, Clone, PartialEq, Debug)]
  +#[repr(C)]
  +pub struct Pixel {
  + xy: (i64, i64),
  + color: Color,
  +}
  +
  +fn main() -> h5::Result<()> {
  + use self::Color::*;
  + use ndarray::{arr1, arr2};
  +
  + {
  + // write
  + let file = h5::File::open("pixels.h5", "w")?;
  + let colors = file.new_dataset::<Color>().create("colors", 2)?;
  + colors.write(&[RED, BLUE])?;
  + let group = file.create_group("dir")?;
  + let pixels = group.new_dataset::<Pixel>().create("pixels", (2, 2))?;
  + pixels.write(&arr2(&[
  + [Pixel { xy: (1, 2), color: RED }, Pixel { xy: (3, 4), color: BLUE }],
  + [Pixel { xy: (5, 6), color: GREEN }, Pixel { xy: (7, 8), color: RED }],
  + ]))?;
  + }
  + {
  + // read
  + let file = h5::File::open("pixels.h5", "r")?;
  + let colors = file.dataset("colors")?;
  + assert_eq!(colors.read_1d::<Color>()?, arr1(&[RED, BLUE]));
  + let pixels = file.dataset("dir/pixels")?;
  + assert_eq!(
  + pixels.read_raw::<Pixel>()?,
  + vec![
  + Pixel { xy: (1, 2), color: RED },
  + Pixel { xy: (3, 4), color: BLUE },
  + Pixel { xy: (5, 6), color: GREEN },
  + Pixel { xy: (7, 8), color: RED },
  + ]
  + );
  + }
  + Ok(())
  +}
  +```
  +
  ## Compatibility
  ### Platforms
  