infoterm 0.1.1

ncurses-compatible terminfo parsing library
Documentation
/// Generic type wrapper used for string expansion.
#[derive(Copy, Clone, Debug)]
pub enum Value<'a> {
    Int(i32),
    Bytes(&'a [u8]),
}

impl Default for Value<'_> {
    fn default() -> Self {
        Value::Int(0)
    }
}

impl From<i32> for Value<'_> {
    fn from(x: i32) -> Self {
        Value::Int(x)
    }
}

impl From<char> for Value<'_> {
    fn from(x: char) -> Self {
        Value::Int(x as _)
    }
}

impl From<bool> for Value<'_> {
    fn from(x: bool) -> Self {
        Value::Int(x as _)
    }
}

impl<'a> From<&'a [u8]> for Value<'a> {
    fn from(x: &'a [u8]) -> Self {
        Value::Bytes(x)
    }
}

impl<'a> From<&'a str> for Value<'a> {
    fn from(x: &'a str) -> Self {
        Value::Bytes(x.as_bytes())
    }
}

impl Value<'_> {
    pub(super) fn increment(self) -> Self {
        match self {
            Value::Int(x) => Value::Int(x + 1),
            Value::Bytes(_) => self,
        }
    }
}