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")
}
}
@Gero87
Copy link

Gero87 commented Feb 24, 2017

Hi,
I have this error, could you help me what there is wrong?

You cannot call a method on a null-valued expression.
At C:\Users\crizzo\Desktop\beta\New folder (2)\credici.ps1:29 char:1

  • $xtw.dispose()
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment