error.rs 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use std::fmt::{self, Display, Formatter};
  2. use std::result;
  3. #[derive(Debug, PartialEq)]
  4. pub enum Error {
  5. BadCharset(String),
  6. UnknownAlgorithm(String),
  7. BadQop(String),
  8. MissingRequired(&'static str, String),
  9. InvalidHeaderSyntax(String),
  10. BadQopOptions(String),
  11. NumParseError,
  12. }
  13. pub type Result<T> = result::Result<T, Error>;
  14. use Error::*;
  15. impl Display for Error {
  16. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  17. match self {
  18. BadCharset(ctx) => write!(f, "Bad charset: {}", ctx),
  19. UnknownAlgorithm(ctx) => write!(f, "Unknown algorithm: {}", ctx),
  20. BadQop(ctx) => write!(f, "Bad Qop option: {}", ctx),
  21. MissingRequired(what, ctx) => write!(f, "Missing \"{}\" in header: {}", what, ctx),
  22. InvalidHeaderSyntax(ctx) => write!(f, "Invalid header syntax: {}", ctx),
  23. BadQopOptions(ctx) => write!(f, "Illegal Qop in prompt: {}", ctx),
  24. NumParseError => write!(f, "Error parsing a number."),
  25. }
  26. }
  27. }
  28. impl From<std::num::ParseIntError> for Error {
  29. fn from(_: std::num::ParseIntError) -> Self {
  30. NumParseError
  31. }
  32. }
  33. impl std::error::Error for Error {}