pub fn write_to<T>(
    value: &T,
    file: &mut io::BufWriter<fs::File>,
    convert_to_json: bool,
) -> Result<()>
where
    T: FeroxSerialize,
{
    // note to future self: adding logging of anything other than error to this function
    // is a bad idea. we call this function while processing records generated by the logger.
    // If we then call log::... while already processing some logging output, it results in
    // the second log entry being injected into the first.

    let contents = if convert_to_json {
        value.as_json()?
    } else {
        value.as_str()
    };

    let contents = strip_ansi_codes(&contents);

    let written = file.write(contents.as_bytes())?;

    if written > 0 {
        // this function is used within async functions/loops, so i'm flushing so that in
        // the event of a ctrl+c or w/e results seen so far are saved instead of left lying
        // around in the buffer
        file.flush()?;
    }

    Ok(())
}
/// Given a string and a reference to a locked buffered file, write the contents and flush
/// the buffer to disk.
Given a string and a reference to a locked buffered file, write the contents and flush
the buffer to disk.
Given a string and a reference to a locked buffered file write the contents and flush the buffer to disk .
pub fn write_to<T>(
    value: &T,
    file: &mut io::BufWriter<fs::File>,
    convert_to_json: bool,
) -> Result<()>
where
    T: FeroxSerialize,
{
    // note to future self: adding logging of anything other than error to this function
    // is a bad idea. we call this function while processing records generated by the logger.
    // If we then call log::... while already processing some logging output, it results in
    // the second log entry being injected into the first.
    let contents = if convert_to_json {
        value.as_json()?
    } else {
        value.as_str()
    };
    let contents = strip_ansi_codes(&contents);
    let written = file.write(contents.as_bytes())?;
    if written > 0 {
        // this function is used within async functions/loops, so i'm flushing so that in
        // the event of a ctrl+c or w/e results seen so far are saved instead of left lying
        // around in the buffer
        file.flush()?;
    }
    Ok(())
}
pub fn write_to < T > ( value : & T , file : & mut io :: BufWriter < fs :: File > , convert_to_json : bool , ) -> Result < ( ) > where T : FeroxSerialize , { // note to future self: adding logging of anything other than error to this function // is a bad idea. we call this function while processing records generated by the logger. // If we then call log::... while already processing some logging output, it results in // the second log entry being injected into the first. let contents = if convert_to_json { value . as_json ( ) ? } else { value . as_str ( ) } ; let contents = strip_ansi_codes ( & contents ) ; let written = file . write ( contents . as_bytes ( ) ) ? ; if written > 0 { // this function is used within async functions/loops, so i'm flushing so that in // the event of a ctrl+c or w/e results seen so far are saved instead of left lying // around in the buffer file . flush ( ) ? ; } Ok ( ( ) ) }
Given a string and a reference to a locked buffered file, write the contents and flush
the buffer to disk.
Given a string and a reference to a locked buffered file write the contents and flush the buffer to disk .
value
&T
file
&mut io::BufWriter<fs::File>
convert_to_json
bool