Code refactoring
Rust Build / Check (pull_request) Successful in 25s
Rust Build / Test Suite (pull_request) Successful in 27s
Rust Build / Rustfmt (pull_request) Successful in 45s
Rust Build / Clippy (pull_request) Failing after 49s
Rust Build / build (pull_request) Successful in 35s

This commit is contained in:
2026-06-06 12:42:34 -04:00
parent 601f8c696f
commit 080f9d6880
+23 -19
View File
@@ -115,35 +115,39 @@ impl NumberParser {
let pars = self.remove_some_data(&phone_number).await;
// println!("Parsed: {pars:?}");
let updated_parsed = self.add_prefix(&pars);
let contact = textsender_models::contact::Contact {
phone_number: updated_parsed,
..Default::default()
match self.add_prefix(&pars) {
Ok(updated_parsed) => {
let contact = textsender_models::contact::Contact {
phone_number: updated_parsed,
..Default::default()
};
updated.push(contact);
}
Err(err) => {
eprintln!("Error: {err:?}");
std::process::exit(-2);
}
};
updated.push(contact);
}
updated
}
fn add_prefix(&self, raw: &String) -> String {
let mut parsed: String = String::new();
let first_char = raw.chars().nth(0).unwrap();
let second_char = raw.chars().nth(1).unwrap();
fn add_prefix(&self, raw: &String) -> Result<String, std::io::Error> {
if raw.is_empty() {
Err(std::io::Error::other("Empty"))
} else {
let mut parsed: String = String::new();
let first_char = raw.chars().nth(0).unwrap();
if first_char == '1' {
parsed = format!("+{raw}");
} else if first_char != '+' {
if second_char != '1' {
parsed = format!("+1{raw}");
} else {
if first_char == '1' {
parsed = format!("+{raw}");
} else if first_char != '+' {
parsed = format!("+1{raw}");
}
}
parsed
Ok(parsed)
}
}
async fn remove_some_data(&self, unparsed: &String) -> String {