Skip to content

Instantly share code, notes, and snippets.

@git314
Created April 23, 2021 02:35
Show Gist options
  • Save git314/252965a918d33a154543f9759b7f6c36 to your computer and use it in GitHub Desktop.
Save git314/252965a918d33a154543f9759b7f6c36 to your computer and use it in GitHub Desktop.
fn main() {
let s = "...".to_string();
let a = vec!["abc","abcde","abcdefgh","abcdefghijkl","abcdefghijklmnop"]
.into_iter()
.map(String::from)
.map(|mut string|
if string.len() > 5 { string.truncate(5); [string, s.to_string()].join("") }
else {string.truncate(5); string})
.collect::<Vec<String>>();
println!("{:?}",a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment