Skip to content

Instantly share code, notes, and snippets.

@kardeiz
Created April 12, 2016 16:04
Show Gist options
  • Save kardeiz/26c303957fc298212c3623c01a26f38c to your computer and use it in GitHub Desktop.
Save kardeiz/26c303957fc298212c3623c01a26f38c to your computer and use it in GitHub Desktop.
Rust stripMargin
pub trait StripMargin {
fn strip_margin(self) -> String;
}
impl StripMargin for &'static str {
fn strip_margin(self) -> String {
let mut out = Vec::new();
for l in self.lines()
.filter(|x| !x.is_empty() ) {
for s in l.splitn(2, '|').nth(1) {
out.push(s);
}
}
out.join("\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment