You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Briefly describe the question, bug or feature request.
When I use write_byte_record with a non-empty iterator after prior series of write_fields, the library produces strange output and may fail with UnequalLengths.
Include a complete program demonstrating a problem.
fnmain() -> Result<(),Box<dyn std::error::Error>>{letmut b = csv::WriterBuilder::new();
b.has_headers(false);letmut csv = b.from_path("out.csv")?;letmut record = csv::ByteRecord::new();
record.push_field(b"12");for _ in0..10000{
csv.write_field("F")?;
csv.write_byte_record(&record)?;}Ok(())}
I used similar code (with a csv.write_field("")? workaround to insert the missing comma), thinking that write_record is only for string records, not byte ones.
What is the observed behavior of the code above?
Output file contains records glued together (except of the last line before UnequalLengths error).
The documentation does not suggest, but also does not explicitly prohibit this combination of csv::Writer methods.
What is the expected or desired behavior of the code above?
write_byte_record's documentation explicitly mentions that it write_field should not be used to prepend fields. Or the program behaves just like as if it were write_record instead.
Maybe usage of write_byte_record after write_field should panic, at least in debug profile.
Here are steps of how similar code can end up in a project:
Example code from write_field's documentation with wtr.write_record(None::<&[u8]>)?; (why there is no dedicated method to avoid those turbofishes?);
None::<&[u8]> gets replaced with a record from other CSV file (e.g. to round trip with prepended fields).
Let's preserve non-UTF-8 content, so ByteRecord instead of StringRecord. As we have switched to byte records, assume (erroneously) that we need to switch to write_byte_record from write_record. It also mentions "more quickly" in the docs, which makes the switch even more attractive.
The text was updated successfully, but these errors were encountered:
What version of the
csv
crate are you using?1.2.2
Briefly describe the question, bug or feature request.
When I use
write_byte_record
with a non-empty iterator after prior series ofwrite_field
s, the library produces strange output and may fail withUnequalLengths
.Include a complete program demonstrating a problem.
I used similar code (with a
csv.write_field("")?
workaround to insert the missing comma), thinking thatwrite_record
is only for string records, not byte ones.What is the observed behavior of the code above?
Output file contains records glued together (except of the last line before
UnequalLengths
error).The documentation does not suggest, but also does not explicitly prohibit this combination of
csv::Writer
methods.What is the expected or desired behavior of the code above?
write_byte_record
's documentation explicitly mentions that itwrite_field
should not be used to prepend fields. Or the program behaves just like as if it werewrite_record
instead.Maybe usage of
write_byte_record
afterwrite_field
should panic, at least in debug profile.Here are steps of how similar code can end up in a project:
write_field
's documentation withwtr.write_record(None::<&[u8]>)?;
(why there is no dedicated method to avoid those turbofishes?);None::<&[u8]>
gets replaced with a record from other CSV file (e.g. to round trip with prepended fields).ByteRecord
instead ofStringRecord
. As we have switched to byte records, assume (erroneously) that we need to switch towrite_byte_record
fromwrite_record
. It also mentions "more quickly" in the docs, which makes the switch even more attractive.The text was updated successfully, but these errors were encountered: