protwrap 0.4.3

Thin protocol wrapper for network applications.
Documentation
use std::{fmt, io};

/// Crate-specific errors.
#[derive(Debug)]
pub enum Error {
  /// Invalid protocol specifier.
  BadProtSpec(String),
  IO(std::io::Error),
  Pki(String)
}

impl Error {
  pub fn bad_protspec(s: impl Into<String>) -> Self {
    Self::BadProtSpec(s.into())
  }

  pub fn pki(s: impl Into<String>) -> Self {
    Self::Pki(s.into())
  }
}

impl std::error::Error for Error {}

impl From<io::Error> for Error {
  fn from(err: io::Error) -> Self {
    Self::IO(err)
  }
}

impl fmt::Display for Error {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match self {
      Self::BadProtSpec(s) => {
        write!(f, "Unable to parse protocol specifier string; {s}")
      }
      Self::IO(s) => {
        write!(f, "I/O; {s}")
      }
      Self::Pki(s) => {
        write!(f, "PKI; {s}")
      }
    }
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :