fn shortest_word_length(text: &str) -> usize {
// split_whitespace handles all whitespace and ignores empty segments
let words = text.split_whitespace();
// Find the minimum length, or return 0 if no words exist
words.map(|w| w.len()).min().unwrap_or(0)
}
fn main() {
let input = "Find the shortest word length in this string";
let result = shortest_word_length(input);
if result == 0 {
println!("No words found.");
} else {
println!("Length of the shortest word: {}", result);
}
}
/*
run:
Length of the shortest word: 2
*/