use buildstructor::buildstructor; use http::header::HeaderName; use http::HeaderValue; use std::error::Error; #[derive(Debug)] pub struct Request { inner: http::Request, } #[buildstructor] impl Request { #[builder] pub fn fake_new( headers: Vec<(K, V)>, uri: Option, method: Option, body: T, ) -> http::Result> where HeaderName: TryFrom, >::Error: Into, HeaderValue: TryFrom, >::Error: Into, { let mut builder = http::request::Builder::new() .method(method.unwrap_or_default()) .uri(uri.unwrap_or_default()); for (key, value) in headers { builder = builder.header(key, value); } let req = builder.body(body)?; Ok(Self { inner: req }) } } fn main() -> Result<(), Box> { let _ = Request::fake_builder() .header(("a".to_string(), "b".to_string())) .header(("a".to_string(), "b".to_string())) .body("") .build() .unwrap(); Ok(()) }