BurntSushi / BurntSushi/rust-csv

csv::ReaderBuilder::from_reader() moves the file reader.

Open
#301 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

Thank you for taking the time to file a bug report. The following describes
some guidelines to creating a minimally useful ticket.

Above all else: do not describe your problem, **SHOW** your problem.

version = "1.2.0"

I have a mixed content scenario in my files:

- other stuff
- csv records
- more other stuff

```
let mut file_reader = std::io::BufReader::new(f);
let mut nfields_string = String::new();
let _ = file_reader
.read_line(&mut nfields_string)
.expect("rankings.txt - could not read first line.");
let mut csv_reader = csv::ReaderBuilder::new()
.has_headers(false)
.trim(csv::Trim::Fields)
.from_reader(file_reader);
// ... no access to because the file_reader has been moved!
// ...
```
This use case is not really supported the way the crate works right now.

The issue also pops up, for example, if you want to dump the remainder of the file into some error log and you use the `Èrror::position()``to seek the file reader and read to end.
And given, that I see sporadic csv reader failures in my application (the cvs records are also written with the csv writer of the same crate), it is hard to track down those sporadic failures in a live environment.

#### Include a complete program demonstrating a problem.
See above for a snippet, showing the inconvenience. The inconvenience is by design. So a working example of how the file_reader is moved is not really helpful.

#### What is the expected or desired behavior of the code above?
The expected behavior is that the `from_reader()` does not move the file reader. Or that there is an alternative, so mixed file content scenarios are supported better.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.