A data model can normalize raw input at the boundary so later code uses consistent fields.

Program

Play the program to choose a raw name and build a normalized user record.

normalized_user_record.rs
struct User {
    name: String,
    role: String,
}

fn main() {
    let raw_name = ;
    let raw_role = "ADMIN";
    let user = User {
        name: raw_name.trim().to_string(),
        role: raw_role.to_lowercase(),
    };
    println!("{}:{}", user.name, user.role);
}
struct User {
    name: String,
    role: String,
}

fn main() {
    let raw_name = ;
    let raw_role = "ADMIN";
    let user = User {
        name: raw_name.trim().to_string(),
        role: raw_role.to_lowercase(),
    };
    println!("{}:{}", user.name, user.role);
}
struct User {
    name: String,
    role: String,
}

fn main() {
    let raw_name = ;
    let raw_role = "ADMIN";
    let user = User {
        name: raw_name.trim().to_string(),
        role: raw_role.to_lowercase(),
    };
    println!("{}:{}", user.name, user.role);
}
struct `User` names the fields that belong together in one record.
normalization `trim` and `to_lowercase` clean raw input before it is stored.
boundary After construction, callers can use `user.name` and `user.role` without re-cleaning.