little-kitty 0.0.3

A low-level interface for the Kitty Graphics Protocol
Documentation
use std::io::*;

//
// ControlValue
//

/// Kitty graphics protocol control value.
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum ControlValue {
    /// Character.
    Char(char),

    /// Unsigned integer.
    UnsignedInteger(u32),

    /// Integer.
    Integer(i32),
}

impl ControlValue {
    /// Write.
    pub fn write<WriteT>(&self, mut writer: WriteT) -> Result<()>
    where
        WriteT: Write,
    {
        match self {
            Self::Char(char_) => write!(writer, "{}", char_),
            Self::UnsignedInteger(unsigned_integer) => write!(writer, "{}", unsigned_integer.to_string()),
            Self::Integer(integer) => write!(writer, "{}", integer.to_string()),
        }
    }
}

impl From<char> for ControlValue {
    fn from(char_: char) -> Self {
        Self::Char(char_)
    }
}

impl From<i32> for ControlValue {
    fn from(integer: i32) -> Self {
        Self::Integer(integer)
    }
}

impl From<u32> for ControlValue {
    fn from(unsigned_integer: u32) -> Self {
        Self::UnsignedInteger(unsigned_integer)
    }
}

impl From<isize> for ControlValue {
    fn from(integer: isize) -> Self {
        (integer as i32).into()
    }
}

impl From<usize> for ControlValue {
    fn from(unsigned_integer: usize) -> Self {
        (unsigned_integer as u32).into()
    }
}