rust3270 0.1.1

rust3270 is a terminal server interface to the IBM 3270 terminal protocol, written in Rust.
Documentation
use crate::server::stream::StreamFormatError;

#[repr(u8)]
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum AID {
    NoAIDGenerated,
    NoAIDGeneratedPrinter,
    StructuredField,
    ReadPartition,
    TriggerAction,
    SysReq,
    PF1,
    PF2,
    PF3,
    PF4,
    PF5,
    PF6,
    PF7,
    PF8,
    PF9,
    PF10,
    PF11,
    PF12,
    PF13,
    PF14,
    PF15,
    PF16,
    PF17,
    PF18,
    PF19,
    PF20,
    PF21,
    PF22,
    PF23,
    PF24,
    PA1,
    PA2,
    PA3,
    Clear,
    ClearPartition,
    Enter,
    SelectorPenAttention,
    MagReaderOperatorID,
    MagReaderNumber,
}

impl From<AID> for u8 {
    fn from(aid: AID) -> u8 {
        use self::AID::*;
        match aid {
            NoAIDGenerated => 0x60,
            NoAIDGeneratedPrinter => 0xE8,
            StructuredField => 0x88,
            ReadPartition => 0x61,
            TriggerAction => 0x7f,
            SysReq => 0xf0,
            PF1 => 0xF1,
            PF2 => 0xF2,
            PF3 => 0xF3,
            PF4 => 0xF4,
            PF5 => 0xF5,
            PF6 => 0xF6,
            PF7 => 0xF7,
            PF8 => 0xF8,
            PF9 => 0xF9,
            PF10 => 0x7A,
            PF11 => 0x7B,
            PF12 => 0x7C,
            PF13 => 0xC1,
            PF14 => 0xC2,
            PF15 => 0xC3,
            PF16 => 0xC4,
            PF17 => 0xC5,
            PF18 => 0xC6,
            PF19 => 0xC7,
            PF20 => 0xC8,
            PF21 => 0xC9,
            PF22 => 0x4A,
            PF23 => 0x4B,
            PF24 => 0x4C,
            PA1 => 0x6C,
            PA2 => 0x6E,
            PA3 => 0x6B,
            Clear => 0x6D,
            ClearPartition => 0x6A,
            Enter => 0x7D,
            SelectorPenAttention => 0x7E,
            MagReaderOperatorID => 0xE6,
            MagReaderNumber => 0xE7,
        }
    }
}

impl TryFrom<u8> for AID {
    type Error = StreamFormatError;

    fn try_from(aid: u8) -> Result<Self, Self::Error> {
        use self::AID::*;
        Ok(match aid {
            0x60 => NoAIDGenerated,
            0xE8 => NoAIDGeneratedPrinter,
            0x88 => StructuredField,
            0x61 => ReadPartition,
            0x7f => TriggerAction,
            0xf0 => SysReq,
            0xF1 => PF1,
            0xF2 => PF2,
            0xF3 => PF3,
            0xF4 => PF4,
            0xF5 => PF5,
            0xF6 => PF6,
            0xF7 => PF7,
            0xF8 => PF8,
            0xF9 => PF9,
            0x7A => PF10,
            0x7B => PF11,
            0x7C => PF12,
            0xC1 => PF13,
            0xC2 => PF14,
            0xC3 => PF15,
            0xC4 => PF16,
            0xC5 => PF17,
            0xC6 => PF18,
            0xC7 => PF19,
            0xC8 => PF20,
            0xC9 => PF21,
            0x4A => PF22,
            0x4B => PF23,
            0x4C => PF24,
            0x6C => PA1,
            0x6E => PA2,
            0x6B => PA3,
            0x6D => Clear,
            0x6A => ClearPartition,
            0x7D => Enter,
            0x7E => SelectorPenAttention,
            0xE6 => MagReaderOperatorID,
            0xE7 => MagReaderNumber,
            _ => return Err(StreamFormatError::InvalidAID { aid }),
        })
    }
}