{"action":"opened","issue":{"url":"https://api.github.com/repos/cybergeek94/multipart/issues/23","labels_url":"https://api.github.com/repos/cybergeek94/multipart/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/cybergeek94/multipart/issues/23/comments","events_url":"https://api.github.com/repos/cybergeek94/multipart/issues/23/events","html_url":"https://github.com/cybergeek94/multipart/issues/23","id":110075072,"number":23,"title":"Usage with hyper's RequestBuilder","user":{"login":"anowell","id":2629687,"avatar_url":"https://avatars.githubusercontent.com/u/2629687?v=3","gravatar_id":"","url":"https://api.github.com/users/anowell","html_url":"https://github.com/anowell","followers_url":"https://api.github.com/users/anowell/followers","following_url":"https://api.github.com/users/anowell/following{/other_user}","gists_url":"https://api.github.com/users/anowell/gists{/gist_id}","starred_url":"https://api.github.com/users/anowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anowell/subscriptions","organizations_url":"https://api.github.com/users/anowell/orgs","repos_url":"https://api.github.com/users/anowell/repos","events_url":"https://api.github.com/users/anowell/events{/privacy}","received_events_url":"https://api.github.com/users/anowell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-06T18:49:16Z","updated_at":"2015-10-06T18:49:16Z","closed_at":null,"body":"I'm finding it quite challenging to retrofit multipart into a client library that was built using hyper's `RequestBuilder`. I've been trying to implement `HttpRequest` and `HttpStream` for a wrapper around hyper's `RequestBuilder` (I can't see an obvious way to implement it directly against RequestBuilder), and perhaps my Rust is still just inadequate, but I keep hitting walls. I've worked around a few limitations of RequestBuilder by handling it very much like SizedRequest in this library (buffer input to a Vec<u8> and defer setting headers until `finish` is called since RequestBuilder consumes self to set headers).\r\n\r\nHowever, I can't seem to call RequestBuilder's `body` method inside `finish` given the trait's lifetimes: RequestBuilder only borrows the buffer, and (if I understand correctly), I can't ensure that self (which owns the buffer) outlives the response (I'm not sure I grok why it even needs to outlive the response, but the borrow checker has defeated me for today.)\r\n\r\nI thought I'd reach out and see if there was an obvious answer that I've been overlooking all along. Are there any examples of multipart used in conjunction with hyper's RequestBuilder? Is this even in-scope for this lib?\r\n\r\n```rust\r\npub struct MultipartBuilder<'a> {\r\n    inner: RequestBuilder<'a, Url>,\r\n    boundary: String,\r\n    buffer: Vec<u8>,\r\n}\r\n\r\nimpl <'a> HttpRequest for MultipartBuilder<'a>  {\r\n    type Stream = Self;\r\n    type Error = HyperError;\r\n\r\n    fn apply_headers(&mut self, boundary: &str, content_len: Option<u64>) -> bool {\r\n        // Can't actually set headers, because RequestBuilder's header method consumes self\r\n        self.boundary = boundary.into();\r\n        true\r\n    }\r\n    fn open_stream(mut self) -> Result<Self::Stream, Self::Error> {\r\n        // Can't actually get RequestBuilder's stream, so we'll buffer it and handle it in `finish`\r\n        self.buffer.clear();\r\n        Ok(self)\r\n    }\r\n\r\n}\r\n\r\nimpl <'a> HttpStream for MultipartBuilder<'a>  {\r\n    type Request = Self;\r\n    type Response = Response;\r\n    type Error = HyperError;\r\n\r\n    fn finish(mut self) -> Result<Self::Response, Self::Error> {\r\n        self.inner\r\n            .header(ContentType(Mime(\r\n                TopLevel::Multipart, SubLevel::Ext(\"form-data\".into()),\r\n                vec![(Attr::Ext(\"boundary\".into()), Value::Ext(self.boundary))]\r\n            )))\r\n            .header(ContentLength(self.buffer.len() as u64))\r\n            .body(&*self.buffer)  // BAD: &*self.buffer doesn't live long enough\r\n            .send()\r\n    }\r\n}\r\n```"}}