fn run<R, W>(input: R, output: W, delimiter: u8) -> Result<(), Report>
where
    R: Read,
    W: Write,
{
    let mut reader = csv::ReaderBuilder::new()
        .has_headers(false)
        .delimiter(delimiter)
        .from_reader(input);

    let mut writer = csv::WriterBuilder::new()
        .has_headers(false)
        .delimiter(delimiter)
        .from_writer(output);

    let mut record_number = 0;
    let mut reader_record = ByteRecord::new();
    let mut writer_record = ByteRecord::new();

    while let Ok(is_more) = reader.read_byte_record(&mut reader_record) {
        if !is_more {
            break;
        }
        reader_record
            .into_iter()
            .enumerate()
            .for_each(|(field_number, field)| {
                let field = cleanse_field(field, delimiter, record_number, field_number);
                writer_record.push_field(field.as_bytes());
            });

        writer.write_byte_record(&writer_record)?;
        reader_record.clear();
        writer_record.clear();
        record_number += 1;
    }

    Ok(())
}
/// Run the program, returning any found errors
Run the program, returning any found errors
Run the program returning any found errors
fn run<R, W>(input: R, output: W, delimiter: u8) -> Result<(), Report>
where
    R: Read,
    W: Write,
{
    let mut reader = csv::ReaderBuilder::new()
        .has_headers(false)
        .delimiter(delimiter)
        .from_reader(input);
    let mut writer = csv::WriterBuilder::new()
        .has_headers(false)
        .delimiter(delimiter)
        .from_writer(output);
    let mut record_number = 0;
    let mut reader_record = ByteRecord::new();
    let mut writer_record = ByteRecord::new();
    while let Ok(is_more) = reader.read_byte_record(&mut reader_record) {
        if !is_more {
            break;
        }
        reader_record
            .into_iter()
            .enumerate()
            .for_each(|(field_number, field)| {
                let field = cleanse_field(field, delimiter, record_number, field_number);
                writer_record.push_field(field.as_bytes());
            });
        writer.write_byte_record(&writer_record)?;
        reader_record.clear();
        writer_record.clear();
        record_number += 1;
    }
    Ok(())
}
fn run < R , W > ( input : R , output : W , delimiter : u8 ) -> Result < ( ) , Report > where R : Read , W : Write , { let mut reader = csv :: ReaderBuilder :: new ( ) . has_headers ( false ) . delimiter ( delimiter ) . from_reader ( input ) ; let mut writer = csv :: WriterBuilder :: new ( ) . has_headers ( false ) . delimiter ( delimiter ) . from_writer ( output ) ; let mut record_number = 0 ; let mut reader_record = ByteRecord :: new ( ) ; let mut writer_record = ByteRecord :: new ( ) ; while let Ok ( is_more ) = reader . read_byte_record ( & mut reader_record ) { if ! is_more { break ; } reader_record . into_iter ( ) . enumerate ( ) . for_each ( | ( field_number , field ) | { let field = cleanse_field ( field , delimiter , record_number , field_number ) ; writer_record . push_field ( field . as_bytes ( ) ) ; } ) ; writer . write_byte_record ( & writer_record ) ? ; reader_record . clear ( ) ; writer_record . clear ( ) ; record_number += 1 ; } Ok ( ( ) ) }
Run the program, returning any found errors
Run the program returning any found errors
input
R
output
W
delimiter
u8
input
R
output
W
delimiter
u8