display_buffered 0.1.0

A small library that provides convinience function to write all the elements into a write with buffering
Documentation
//! Provides convinience function to write all the elements into a write with buffering

use std::{
    fmt::Display,
    io::{self, BufWriter, Write},
};

/// Writes all the items into the writer with buffering sepparating them with the new line
///
/// # Arguments
///
/// * values - slice of values to print
/// * buf - buffer to write into
///
/// # Errors
///
/// Errors if the writing or flushing the buffer errors
///
/// # Example
///
/// ```
/// use display_buffered::display_buffered;
///
/// use std::io::stdout;
///
/// display_buffered([10, 20, 30], stdout()).unwrap()
/// ```
pub fn display_buffered<I, T, W>(values: I, writer: W) -> Result<(), io::Error>
where
    T: Display,
    I: IntoIterator<Item = T>,
    W: Write,
{
    let mut writer = BufWriter::new(writer);

    for item in values {
        writeln!(writer, "{item}")?
    }

    writer.flush()
}