Make RequestBuilder more easily extensible
RequestBuilder has a great API, and I often find myself wanting to be able to extend it with some project-specific functionality without having to wrap and recreate that API. For example: say my project has a custom header we like to insert in requests. I'll do something like:
pub trait RequestBuilderExts {
fn with_my_custom_header(self, ...) -> Self;
}
impl RequestBuilderExts for reqwest::RequestBuilder {
fn with_my_custom_header(self, ...) -> Self {
...
}
}
So now this fits seamlessly in with the rest of the RequestBuilder API without having to wrap it. The problem is that my extension function doesn't have access to everything that reqwest::RequestBuilder does, so, for example, if the header I want to insert needs to be converted into a HeaderValue, which could fail, I don't have a way to propagate that error in the builder like reqwest does (which sets self.request to an Err). It'd be great to have some way to get access to that to enable extension functions like this one to be able to behave more like "first class citizens", so functionality can be added without having to wrap/proxy the entire type. (ClientBuilder could also benefit from this, I think).
(...Or maybe there's a different approach to accomplish something like this? Would love to know how, if so!)