This is probably very basic but it's stymied me so far.
I am writing something that will read several large line-based logfiles and process them in order of line timestamp—so I want to have a bunch of them open in parallel, reading one line off this, one line off that. Some of these logfiles may be gz- or xz-compressed. What I ideally want to do is to take the filename, send it to an opener function based on type, and get a BufReader back.
I can use File::open
and I can use Command::new
(to run xzcat or zcat), but they return different types (a File
or a ChildStdout
). I can in principle feed both of those into a BufReader::new
, but I get different BufReader types out as a result. (Yes, I know there are compression libraries. That may be part of the solution.)
Even if I use plain old cat
rather than File::open
so that I'm only dealing with one one type BufReader<ChildStdout>
, I still can't pass it as a parameter to a fn getnextline
— the compiler says I need something that looks like fn getnextline<R>(b: BufReader<R>)
, so I do that, but then it turns out that b
doesn't have a read_line
method.
let l = b.read_line(&mut line);
^^^^^^^^^ method not found in `BufReader<ChildStdout>`
(Ultimately I'm going to want to put all these bufreaders in a vec, so…. do I need some kind of composite type which can be any BufReader? A custom struct or enum?)