use crate::diagnostic::Parsed;
use crate::error::ParseError;
pub(crate) mod sealed {
pub trait Sealed {}
}
pub trait HeaderParse: Sized + sealed::Sealed {
fn parse_with_warnings(input: &str) -> Result<Parsed<Self>, ParseError>;
fn parse(input: &str) -> Result<Self, ParseError> {
Self::parse_with_warnings(input).map(|parsed| parsed.value)
}
fn parse_strict(input: &str) -> Result<Self, ParseError> {
Self::parse_with_warnings(input)?.into_strict()
}
}
pub trait ListParse: HeaderParse {
fn from_entries_with_warnings<'a>(
entries: impl IntoIterator<Item = &'a str>,
) -> Result<Parsed<Self>, ParseError>;
fn from_entries<'a>(entries: impl IntoIterator<Item = &'a str>) -> Result<Self, ParseError> {
Self::from_entries_with_warnings(entries).map(|parsed| parsed.value)
}
fn from_entries_strict<'a>(
entries: impl IntoIterator<Item = &'a str>,
) -> Result<Self, ParseError> {
Self::from_entries_with_warnings(entries)?.into_strict()
}
fn from_rows_with_warnings<'a>(
rows: impl IntoIterator<Item = &'a str>,
) -> Result<Parsed<Self>, ParseError>;
fn from_rows<'a>(rows: impl IntoIterator<Item = &'a str>) -> Result<Self, ParseError> {
Self::from_rows_with_warnings(rows).map(|parsed| parsed.value)
}
fn from_rows_strict<'a>(rows: impl IntoIterator<Item = &'a str>) -> Result<Self, ParseError> {
Self::from_rows_with_warnings(rows)?.into_strict()
}
}
pub trait UriHeaderParse: HeaderParse {
fn parse_uri_header_with_warnings(raw: &str) -> Result<Parsed<Self>, ParseError>;
fn parse_uri_header(raw: &str) -> Result<Self, ParseError> {
Self::parse_uri_header_with_warnings(raw).map(|parsed| parsed.value)
}
fn parse_uri_header_strict(raw: &str) -> Result<Self, ParseError> {
Self::parse_uri_header_with_warnings(raw)?.into_strict()
}
}