use anyhow::Result; use byteorder::ByteOrder; use gauge_mac_tool::GaugeMacCommand; use gauge_mac_tool::GaugeMacReader; #[derive(GaugeMacCommand)] #[reg(0x04)] struct Foo { addr: u16, one_byte: u8, two_byte: u16, } #[derive(GaugeMacCommand)] struct Bar { addr: u16, } struct DummyGague {} impl GaugeMacReader for DummyGague { fn fetch_mac_data(&self, addr: u16) -> Result<[u8; 36]> { let mut buf = [0u8; 36]; buf[0] = (addr / 0xff) as u8; buf[1] = (addr % 0xff) as u8; buf[2] = 0x11_u8; buf[3] = 0x12_u8; buf[4] = 0x34_u8; Ok(buf) } } #[test] fn it_works() { let gauge = DummyGague {}; let foo = Foo::build_from_gauge(gauge).unwrap(); assert_eq!(foo.addr, 0x04); assert_eq!(foo.one_byte, 0x11); assert_eq!(foo.two_byte, 0x1234); } #[test] fn missing_reg_attribute() { let gauge = DummyGague {}; let bar = Bar::build_from_gauge(gauge).unwrap(); assert_eq!(bar.addr, 0x0); }