Each Chinese character has three bytes. So your code in table.rs will cause a panic.
fn truncate_middle(row: &str, max_length: u16) -> String {
if row.len() as u16 > max_length {
let first_slice = &row[0..(max_length as usize / 2) - 2];
let second_slice = &row[(row.len() - (max_length / 2) as usize + 2)..row.len()];
format!("{}[..]{}", first_slice, second_slice)
} else {
row.to_string()
}
}
like that:
let s = "中文";
let s = &s[0..2];
panicked at 'byte index 2 is not a char boundary; it is inside '中' (bytes 0..3) of 中文
Each Chinese character has three bytes. So your code in
table.rswill cause a panic.like that:
panicked at 'byte index 2 is not a char boundary; it is inside '中' (bytes 0..3) of
中文