use crate::{
field::{metadata::block, text::IntError},
payload::response,
uri,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Plan {
form: block::Form,
scheme: uri::Scheme,
authority: block::Authority,
method: response::Method,
length: Option<u64>,
}
impl Plan {
pub(super) const fn new(
form: block::Form,
scheme: uri::Scheme,
source: block::Authority,
method: response::Method,
length: Option<u64>,
) -> Self {
Self {
form,
scheme,
authority: source,
method,
length,
}
}
pub const fn form(self) -> block::Form {
self.form
}
pub const fn scheme(self) -> uri::Scheme {
self.scheme
}
pub const fn authority(self) -> block::Authority {
self.authority
}
pub const fn method(self) -> response::Method {
self.method
}
pub fn try_length(self) -> Result<Option<usize>, IntError> {
match self.length.map(usize::try_from).transpose() {
Ok(length) => Ok(length),
Err(_) => Err(IntError::Overflow),
}
}
}