I'm learning rust and I've decided to do it by doing algorithms. Is the code below idiomatic rust or (perhaps yes), could be written better?
Thank you.
pub fn longest_common_prefix(strs: Vec<String>) -> String {
let mut i = 0;
let first_str = &strs[0];
'outer: while i < first_str.len() {
for j in 0..strs.len() {
match strs[j].chars().nth(i) {
Some(cx) => {
if cx != first_str.chars().nth(i).unwrap() {
break 'outer;
}
}
None => break 'outer,
}
}
i += 1;
}
let res: String = first_str[0..i].to_string();
res
}