Get length of longest String in a Vec in Rust

Category: rust, year: 2021

The following code snippet is an example of how to find out the length of the longest String in a Vec using Rust:

let string_vec = vec!["One", "Two", "Three", "Twenty"];
let max_string_length = string_vec.iter().map(|t| t.len()).max().unwrap();
eprintln!("Max string length: {}", max_string_length);

Tags: rust string


Archive
Full Index

linux (4)
cpp (3)
rust (2)
macos (1)
matplotlib (1)
unix (1)


Tags List