// https://play.rust-lang.org/?gist=d5d36e5991690804f5ee539ff1fafc4d&version=stable&mode=debug
#![allow(unused)]
fn main() {
let line = "abc";
let f = get_add_function(">>>>");
println!("{}", f(line));
}
pub fn get_add_function<'a>(indent: &'a str) -> impl (Fn(&str) -> String) + 'a {
move |line: &str| {
if indent.is_empty() {
line.to_string()
} else {
let mut s = String::with_capacity(line.len() + indent.len());
s.push_str(indent);
s.push_str(line);
s
}
}
}
Comments