Repository: gsquire/sendgrid-rs (language: rust)

Issue:
Set Subject for Personalization
How can I set subject of Personalization struct? https://github.com/gsquire/sendgrid-rs/blob/master/src/v3.rs#L335



Discussion / hints:

Fix patch:
diff --git a/src/client.rs b/src/client.rs
index 94a770c..bfc584e 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -47,30 +47,30 @@ fn make_post_body(mut mail_info: Mail) -> SendgridResult<String> {
     }
 
     for cc in mail_info.cc.iter() {
-        encoder.append_pair("cc[]", &cc);
+        encoder.append_pair("cc[]", cc);
     }
 
     for bcc in mail_info.bcc.iter() {
-        encoder.append_pair("bcc[]", &bcc);
+        encoder.append_pair("bcc[]", bcc);
     }
 
     for (attachment, contents) in &mail_info.attachments {
-        encoder.append_pair(&make_form_key("files", attachment), &contents);
+        encoder.append_pair(&make_form_key("files", attachment), contents);
     }
 
     for (id, value) in &mail_info.content {
-        encoder.append_pair(&make_form_key("content", id), &value);
+        encoder.append_pair(&make_form_key("content", id), value);
     }
 
-    encoder.append_pair("from", &mail_info.from);
-    encoder.append_pair("subject", &mail_info.subject);
-    encoder.append_pair("html", &mail_info.html);
-    encoder.append_pair("text", &mail_info.text);
-    encoder.append_pair("fromname", &mail_info.from_name);
-    encoder.append_pair("replyto", &mail_info.reply_to);
-    encoder.append_pair("date", &mail_info.date);
+    encoder.append_pair("from", mail_info.from);
+    encoder.append_pair("subject", mail_info.subject);
+    encoder.append_pair("html", mail_info.html);
+    encoder.append_pair("text", mail_info.text);
+    encoder.append_pair("fromname", mail_info.from_name);
+    encoder.append_pair("replyto", mail_info.reply_to);
+    encoder.append_pair("date", mail_info.date);
     encoder.append_pair("headers", &mail_info.make_header_string()?);
-    encoder.append_pair("x-smtpapi", &mail_info.x_smtpapi);
+    encoder.append_pair("x-smtpapi", mail_info.x_smtpapi);
 
     Ok(encoder.finish())
 }
diff --git a/src/v3.rs b/src/v3.rs
index 50c1302..39f4a57 100644
--- a/src/v3.rs
+++ b/src/v3.rs
@@ -386,6 +386,14 @@ impl Personalization {
         self
     }
 
+    /// Add a substitutions field.
+    pub fn add_substitutions(mut self, substitutions: SGMap) -> Personalization {
+        self.substitutions
+            .get_or_insert_with(|| SGMap::with_capacity(substitutions.len()))
+            .extend(substitutions);
+        self
+    }
+
     /// Add a dynamic template data field.
     pub fn add_dynamic_template_data(mut self, dynamic_template_data: SGMap) -> Personalization {
         // We can safely unwrap & unreachable here since SGMap will always serialize
@@ -414,6 +422,18 @@ impl Personalization {
             .extend(new_vals);
         Ok(self)
     }
+
+    /// Set the subject.
+    pub fn set_subject(mut self, subject: &str) -> Personalization {
+        self.subject = Some(String::from(subject));
+        self
+    }
+
+    /// Set send at.
+    pub fn set_send_at(mut self, send_at: u64) -> Personalization {
+        self.send_at = Some(send_at);
+        self
+    }
 }
 
 impl Attachment {


Test patch: