async_labjack 0.1.0

A pure rust, async interface to the LabJack T-series via Modbus TCP
Documentation
/// From https://stackoverflow.com/questions/28028854/how-do-i-match-enum-values-with-an-integer/57578431#57578431
/// This macro wraps an enum and adds a TryFrom implementation, which lets you take a u16
/// and get the resultant enum value for it. Valid only for enums holding u16s.
macro_rules! back_to_enum {
    ($(#[$meta:meta])* $vis:vis enum $name:ident {
        $($(#[$vmeta:meta])* $vname:ident $(= $val:expr)?,)*
    }) => {
        $(#[$meta])*
        $vis enum $name {
            $($(#[$vmeta])* $vname $(= $val)?,)*
        }

        impl std::convert::TryFrom<u16> for $name {
            type Error = crate::Error;

            fn try_from(v: u16) -> std::result::Result<Self, Self::Error> {
                match v {
                    $(x if x == $name::$vname as u16 => Ok($name::$vname),)*
                    _ => Err(crate::Error::UnknownStatusCode(v)),
                }
            }
        }
    }
}

pub(crate) use back_to_enum;