Find why this apparently bounded prefix helper can panic.
Rust
fn prefix(text: &str, max_bytes: usize) -> &str {
&text[..max_bytes.min(text.len())]
}
fn main() {
println!("{}", prefix("用户", 4));
}
fn prefix(text: &str, max_bytes: usize) -> &str {
&text[..max_bytes.min(text.len())]
}
fn main() {
println!("{}", prefix("用户", 4));
}