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.
Rust code shared from the playground
#[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[..]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment