Created
December 16, 2016 23:55
-
-
Save anonymous/15d47d83be6c38665eb09fa88d4e7e3e to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
| #[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