Repository: lettre/lettre (language: rust)

Issue:
Function to convert `transport::smtp::response::Code` to integer
**Is your feature request related to a problem? Please describe.**

I want to store a response code as a integer type in my database.

**Describe the solution you'd like**

I'd like a function on the `transport::smtp::response::Code` type to convert it in into a integer.

**Describe alternatives you've considered**

N/A

**Additional context**

N/A


Discussion / hints:

Fix patch:
diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs
index 403162b65..990a22c45 100644
--- a/src/transport/smtp/response.rs
+++ b/src/transport/smtp/response.rs
@@ -132,6 +132,12 @@ impl Code {
     }
 }
 
+impl From<Code> for u16 {
+    fn from(code: Code) -> Self {
+        code.detail as u16 + 10 * code.category as u16 + 100 * code.severity as u16
+    }
+}
+
 /// Contains an SMTP reply, with separated code and message
 ///
 /// The text message is optional, only the code is mandatory
@@ -317,6 +323,17 @@ mod test {
         assert_eq!(code.to_string(), "421");
     }
 
+    #[test]
+    fn test_code_to_u16() {
+        let code = Code {
+            severity: Severity::TransientNegativeCompletion,
+            category: Category::Connections,
+            detail: Detail::One,
+        };
+        let c: u16 = code.into();
+        assert_eq!(c, 421);
+    }
+
     #[test]
     fn test_response_from_str() {
         let raw_response = "250-me\r\n250-8BITMIME\r\n250-SIZE 42\r\n250 AUTH PLAIN CRAM-MD5\r\n";


Test patch: