A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Longest Word in Rust page! Here, you'll find the source code for this program as well as a description of how the program works.
use std::env::args;
use std::process::exit;
fn usage() -> ! {
println!("Usage: please provide a string");
exit(0);
}
fn get_longest_word_len(s: &str) -> usize {
s.trim()
.split_whitespace()
.map(|t| t.len())
.max()
.unwrap()
}
fn main() {
let mut args = args().skip(1);
// Exit if 1st command-line argument is empty
let s: &str = &args
.next()
.unwrap_or_else(|| usage());
if s.len() < 1 {
usage();
}
// Get longest word length and display it
println!("{}", get_longest_word_len(s));
}
Longest Word in Rust was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.