Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#![feature(assoc_char_funcs)]
use std::collections::VecDeque;
use std::iter::FromIterator;
fn main() -> Result<(), failure::Error> {
let a = "Hello World";
dbg!(a
.split(" ")
.fold(String::with_capacity(a.len()), |mut acc, w| {
let mut s: VecDeque<char> = w.chars().collect();
if s.len() > 2 {
s.swap(1, s.len() - 1);
}
if let Some(c) = s.pop_front() {
let v: Vec<char> = format!("{}", c as u32).chars().collect();
v.into_iter().rev().for_each(|ch| s.push_front(ch));
}
acc.push_str(&String::from_iter(s));
acc.push(' ');
acc
}).trim_end());
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment