From fa8683a54b0056f4cc31d096765de373f8ae8a43 Mon Sep 17 00:00:00 2001 From: ItsMeShashank Date: Mon, 8 May 2023 19:05:08 +0530 Subject: [PATCH] enhancement(common_utils): impl deref for email newtype (#1073) --- crates/common_utils/src/pii.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/common_utils/src/pii.rs b/crates/common_utils/src/pii.rs index d4b94c1a19..30c51b29e7 100644 --- a/crates/common_utils/src/pii.rs +++ b/crates/common_utils/src/pii.rs @@ -1,6 +1,6 @@ //! Personal Identifiable Information protection. -use std::{convert::AsRef, fmt, str::FromStr}; +use std::{convert::AsRef, fmt, ops, str::FromStr}; use diesel::{ backend, @@ -122,6 +122,20 @@ where #[diesel(sql_type = diesel::sql_types::Text)] pub struct Email(Secret); +impl ops::Deref for Email { + type Target = Secret; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ops::DerefMut for Email { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + impl Queryable for Email where DB: Backend,