I'm writing the below helpers to use them everywhere in my app like this:
impl Player {
pub fn set_email(&mut self, mut email: String) -> Result<()> {
trim_all_spaces(&mut email);
if email.is_empty() {
// return Err
}
self.email = email;
Ok(())
}
fn set_firstname(&mut self, mut firstname: String) -> Result<()> {
to_name(&mut firstname);
if firstname.is_empty() {
// return Err
}
self.firstname = firstname;
Ok(())
}
}
pub fn trim_all_spaces(s: &mut String) {
s.retain(|c| !c.is_whitespace());
}
pub fn to_name(s: &mut String) {
trim_useless_space(s);
s.retain(|c| c.is_whitespace() || c.is_alphabetic());
*s = s.trim().to_string();
}
Is this an idiomatic way of writing these helpers?