These are chat archives for rust-lang/rust

19th
Jul 2017
Nikolay Denev
@ndenev
Jul 19 2017 11:27

Hi, I'm having some trouble figuring out how to do something so I'm hoping someone can have idea.
Basically I'm trying to implement Iterator over a file that reads data in chunks using BufReader's fill_buff() and consume(),
and then parse the variably sized records using NOM. The thing is when I reach the end of the first 8k buffer I have some data left
in it but it's not enough to parse next record so NOM returns IResult::Incomplete and then I call fill_buff() again but I'm getting the same buffer back.
Do I have to consume the whole buffer so that it gets refilled? This means probably that I have to store this remainder somewhere?

So, I just mmap-ed the file using the memmap crate, which seems to work fine. There is just a tiny bit of unsafe to get the mmaped file as byte slice.

Ashley Davis
@dualmoon
Jul 19 2017 22:45
let args: Vec<usize> = argument.split("d").map(|s| s.parse().unwrap()).collect();
how can i expand this to check that s.parse() doesn't overflow?
Max Frai
@max-frai
Jul 19 2017 22:48
@dualmoon unwrap_or ? If not, describe what you want in case when it's overflow
Ashley Davis
@dualmoon
Jul 19 2017 22:52
oh, that was easier than i expected, thanks boss
Ashley Davis
@dualmoon
Jul 19 2017 23:17
any built-in way to count how many times a vector contains a given element?
Max Frai
@max-frai
Jul 19 2017 23:23
I don't think there is built-in fast way. As an example, you can use find on iterator, collect and count the results :)