hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

refactor: use newtype pattern for email addresses

Open nachiketkanore opened this issue 2 years ago • 7 comments

Type of Change

  • [ ] Bugfix
  • [x] New feature
  • [x] Enhancement
  • [ ] Refactoring
  • [ ] Dependency updates

Description

  • This fixes #608
  • Added testcases

Additional Changes

  • [ ] This PR modifies the database schema
  • [ ] This PR modifies application configuration/environment variables

Motivation and Context

#608

How did you test it?

  • ran cargo test
  • Added 2 unit testcases for validation of implemented code
  • img

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [x] I addressed lints thrown by cargo clippy
  • [x] I reviewed submitted code
  • [x] I added unit tests for my changes where possible
  • [x] I added a CHANGELOG entry if applicable

nachiketkanore avatar Mar 31 '23 09:03 nachiketkanore

  • Shouldn't std::fmt::Debug be implemented for struct Email(Secret<String>)? Since, we will be calling format!(email) where email: Email(Secret<String>)
  • So, Email(Secret<String>) will replace both Email(String) and Secret<String, Email>? @SanchithHegde

nachiketkanore avatar Apr 01 '23 09:04 nachiketkanore

  • Shouldn't std::fmt::Debug be implemented for struct Email(Secret)? Since, we will be calling format!(email) where email: Email(Secret)

You should be able to derive Debug on Email(Secret<String>) since Secret implements Debug already.

  • So, Email(Secret) will replace both Email(String) and Secret<String, Email>?

I'm not sure if there are any types of the form Email(String) in our code. But if there are any, please do replace that and Secret<String, Email> with Email(Secret<String>).

SanchithHegde avatar Apr 01 '23 10:04 SanchithHegde

let secret: Secret<String, Email> = Secret::new("[email protected]".to_string());
assert_eq!("*******@gmail.com", format!("{secret:?}"));

What about these tests?

nachiketkanore avatar Apr 01 '23 10:04 nachiketkanore

You'd have to update/remove tests accordingly.

SanchithHegde avatar Apr 01 '23 10:04 SanchithHegde

Sorry, this got closed by mistake. I was trying to sync with the remote, but somehow the PR closed.

nachiketkanore avatar Apr 12 '23 14:04 nachiketkanore

Done

nachiketkanore avatar Apr 26 '23 16:04 nachiketkanore

Done Made suggested changes

nachiketkanore avatar Apr 27 '23 13:04 nachiketkanore