about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T13·33+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T13·33+0100
commit718d9457535d47c5c1f04d8d7a7bdff07ff0bad5 (patch)
treef37724a0f71e01100d1865f51df0c5e8667f7c0d
parentc6c17464288848aba045d4dbd6ee06fb8925f1b9 (diff)
refactor: Use `mut self`-consuming builder functions
Writing the functions this way makes it slightly nicer to chain them
without having to assign the request to an intermediate variable.
-rw-r--r--src/lib.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 88e47c0bf948..b04f0cec3ef5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -78,28 +78,27 @@ impl <'a> Request<'a> {
     }
 
     /// Add a header to a request.
-    pub fn header(&mut self, k: &str, v: &str) -> CurlResult<&mut Self> {
+    pub fn header(mut self, k: &str, v: &str) -> CurlResult<Self> {
         self.headers.append(&format!("{}: {}", k, v))?;
         Ok(self)
     }
 
     /// Set the User-Agent for this request.
-    pub fn user_agent(&mut self, agent: &str) -> CurlResult<&mut Self> {
+    pub fn user_agent<'b: 'a>(mut self, agent: &str) -> CurlResult<Self> {
         self.handle.useragent(agent)?;
         Ok(self)
     }
 
     /// Add a byte-array body to a request using the specified
     /// Content-Type.
-    pub fn body(&'a mut self, content_type: &'a str, data: &'a [u8]) -> &mut Self {
+    pub fn body(mut self, content_type: &'a str, data: &'a [u8]) -> Self {
         self.body = Body::Bytes { data, content_type };
         self
     }
 
     /// Add a JSON-encoded body from a serializable type.
     #[cfg(feature = "json")]
-    pub fn json<T: Serialize>(&'a mut self, body: &T)
-                              -> Result<&mut Self, serde_json::Error> {
+    pub fn json<T: Serialize>(mut self, body: &T) -> Result<Self, serde_json::Error> {
         let json = serde_json::to_vec(body)?;
         self.body = Body::Json(json);
         Ok(self)