infoterm 0.1.1

ncurses-compatible terminfo parsing library
Documentation
//! Capability names and indices.
//!
//! The names are those listed in X/Open curses, issue 7, in the index order used by ncurses.\
//! Enums are marked `#[non_exhaustive]` in the unlikely event that new capabilities are added.\
//! ncurses-internal capabilities are not exposed as they're not part of the public API.
//!
//! Conversion to and from strings is possible using the [`Display`][std::fmt::Display] and
//! [`FromStr`][std::str::FromStr] traits, and to and from integers using [`Into`] and [`TryFrom`].
//!
//! For `Display`, `{}` gives the short name, and `{:#}` the long name.\
//! For `FromStr`, both short and long names are allowed.

#[macro_use]
mod macros;
mod boolean;
mod integer;
mod string;

use std::error::Error;
use std::fmt::{self, Display, Formatter};

pub use boolean::*;
pub use integer::*;
pub use string::*;

/// Error returned when parsing a capability using `FromStr` fails.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct ParseCapabilityError;

impl Display for ParseCapabilityError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        "provided string did not match any capabilities".fmt(f)
    }
}

impl Error for ParseCapabilityError {}

/// Error returned when checked conversion from a capability index fails.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct IndexOutOfRangeError;

impl Display for IndexOutOfRangeError {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        "provided index is out of range".fmt(f)
    }
}

impl Error for IndexOutOfRangeError {}