use std::collections::HashMap; use crate::response::{self, Response}; #[derive(Debug, Clone, Copy)] pub struct Builder; #[derive(Debug, Clone, Copy)] pub struct Status { status: response::Status, } #[derive(Debug, Clone)] pub struct Header { status: response::Status, headers: HashMap>, } impl Builder { pub fn new() -> Self { Self } pub fn status(self, status: response::Status) -> Status { Status { status } } } impl Status { pub fn headers, V: Into>, T: IntoIterator>( self, headers: T, ) -> Header { Header { status: self.status, headers: HashMap::from_iter( headers .into_iter() .map(|(key, value)| (key.into(), value.into())), ), } } pub fn body(self, body: response::Body) -> Response { Response { status: self.status, headers: HashMap::new(), body, } } } impl Header { pub fn headers, V: Into>, T: IntoIterator>( self, headers: T, ) -> Header { Header { status: self.status, headers: HashMap::from_iter( headers .into_iter() .map(|(key, value)| (key.into(), value.into())), ), } } pub fn body(self, body: response::Body) -> Response { Response { status: self.status, headers: self.headers, body, } } }