Created
April 12, 2016 16:04
-
-
Save kardeiz/26c303957fc298212c3623c01a26f38c to your computer and use it in GitHub Desktop.
Rust stripMargin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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