Skip to content

Commit

Permalink
refactor: improve contact builder methods
Browse files Browse the repository at this point in the history
this is a result from linting

Option::is_some is also more readable

Use String::new(), as it's cleaner and apparently more efficient
  • Loading branch information
jasonribble committed Jul 29, 2024
1 parent 4e5c393 commit 7dce60b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/models/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ impl Builder {
) -> Result<Self, AppError> {
let maybe_email = email.as_deref().unwrap_or("");

if utils::is_not_valid_email(maybe_email) && email != None {
if utils::is_not_valid_email(maybe_email) && Option::is_some(&email) {
return Err(AppError::InvalidEmail(
email.clone().unwrap_or_else(|| String::from("")),
email.clone().unwrap_or_else(|| String::new()),
));
}

let maybe_phone = phone_number.as_deref().unwrap_or("");

if utils::is_not_valid_phone_number(maybe_phone) && phone_number != None {
if utils::is_not_valid_phone_number(maybe_phone) && Option::is_some(&email) {
return Err(AppError::InvalidPhoneNumber(
phone_number.clone().unwrap_or_else(|| String::from("")),
phone_number.clone().unwrap_or_else(|| String::new()),
));
}

Expand All @@ -81,7 +81,7 @@ impl Builder {
}

#[allow(dead_code)]
pub fn is_empty(&self) -> bool {
const fn is_empty(&self) -> bool {
self.update.first_name.is_none()
&& self.update.last_name.is_none()
&& self.update.display_name.is_none()
Expand Down

0 comments on commit 7dce60b

Please sign in to comment.