Function tmx_utils::string_ext::format_list_slices
source · pub fn format_list_slices(list: &Vec<&str>) -> StringExpand description
Formats a list of string slices with commas and “and” if necessary. Uses the oxford comma.
Note: An attempt was made to genericize these functions to work with Vec<T : Display + Join>, but the Join trait is unstable.
Examples
assert_eq!(format_list_slices(
&vec![]),
"nothing");assert_eq!(format_list_slices(&vec![
"Nona"]),
"Nona");assert_eq!(format_list_slices(&vec![
"Nona", "Samantha"]),
"Nona and Samantha");assert_eq!(format_list_slices(&vec![
"Nona", "Samantha", "Lucy", "Charles"]),
"Nona, Samantha, Lucy, and Charles");