use std::{borrow::Cow, collections::HashSet};
use crate::hyper::http::HeaderName;
#[derive(Debug, Clone)]
pub enum Report {
Match,
Mismatch(HashSet<Reason>),
}
impl From<bool> for Report {
fn from(value: bool) -> Self {
match value {
true => Self::Match,
false => Self::Mismatch(HashSet::default()),
}
}
}
impl From<Vec<Reason>> for Report {
fn from(value: Vec<Reason>) -> Self {
if value.is_empty() {
Self::Match
} else {
Self::Mismatch(value.into_iter().collect())
}
}
}
impl From<Option<Reason>> for Report {
fn from(value: Option<Reason>) -> Self {
match value {
None => Self::Match,
Some(reason) => {
#[allow(clippy::mutable_key_type)]
let mut reasons = HashSet::new();
reasons.insert(reason);
Self::Mismatch(reasons)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Reason {
Method,
Uri,
Header(HeaderName),
Body,
}
impl Reason {
pub fn as_str(&self) -> Cow<'static, str> {
match self {
Self::Method => "method".into(),
Self::Uri => "uri".into(),
Self::Header(name) => format!("header `{name}`").into(),
Self::Body => "body".into(),
}
}
}