Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2016 23:55
Show Gist options
  • Save anonymous/15d47d83be6c38665eb09fa88d4e7e3e to your computer and use it in GitHub Desktop.
Save anonymous/15d47d83be6c38665eb09fa88d4e7e3e to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 16, 2016.
    19 changes: 19 additions & 0 deletions playground.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #[macro_use]
    extern crate nom;
    use std::str;

    named!(split<&[u8], (&str, &str, &str, &str)>, do_parse!(
    v1: map_res!(take_until!(","), str::from_utf8) >>
    tag!(",") >>
    v2: map_res!(take_until!(","), str::from_utf8) >>
    tag!(",") >>
    v3: map_res!(take_until!(","), str::from_utf8) >>
    tag!(",") >>
    v4: map_res!(take_until!(","), str::from_utf8) >>
    (v1, v2, v3, v4)
    ));

    fn main() {
    let first_line = b"value1,value2,value3,value4";
    println!("{:?}", split(&first_line[..]));
    }