const PHONE_MASK: &str = "(___) ___-____"; const ZERO: u8 = '0' as u8; fn create_phone_number(numbers: &[u8]) -> String { let mut position = 0; PHONE_MASK .chars() .map(|c| match c { '_' => { let c = (numbers[position] + ZERO) as char; position += 1; c } c => c, }) .collect() } #[test] fn returns_expected() { assert_eq!( create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890" ); assert_eq!( create_phone_number(&[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), "(111) 111-1111" ); assert_eq!( create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 9]), "(123) 456-7899" ); }