Skip to main content

HttpCsvWriter

Struct HttpCsvWriter 

Source
pub struct HttpCsvWriter { /* private fields */ }
Expand description

HTTP CSV writer that generates CSV files in memory for streaming responses

This writer generates the entire CSV file in memory and can be used to stream responses in web servers. Supports optional compression.

§Example

use excelstream::HttpCsvWriter;

let mut writer = HttpCsvWriter::new();
writer.write_row(&["ID", "Name", "Value"])?;
writer.write_row(&["1", "Alice", "100"])?;
writer.write_row(&["2", "Bob", "200"])?;

let csv_bytes = writer.finish()?;
// Send csv_bytes as HTTP response body

Implementations§

Source§

impl HttpCsvWriter

Source

pub fn new() -> Self

Create a new HTTP CSV writer (uncompressed)

§Example
use excelstream::HttpCsvWriter;

let mut writer = HttpCsvWriter::new();
writer.write_row(&["Name", "Age"])?;
writer.write_row(&["Alice", "30"])?;

let bytes = writer.finish()?;
Source

pub fn with_compression(compression_level: u32) -> Self

Create a new HTTP CSV writer with Deflate/Gzip compression

§Arguments
  • compression_level - Compression level from 0 to 9:
    • 0: No compression (fastest)
    • 1: Fast compression
    • 6: Balanced (recommended)
    • 9: Maximum compression (slowest)

Note: HTTP streaming only supports Deflate compression. For Zstd compression, use file-based CsvWriter instead.

§Example
use excelstream::HttpCsvWriter;

let mut writer = HttpCsvWriter::with_compression(6);
writer.write_row(&["Name", "Age"])?;
writer.write_row(&["Alice", "30"])?;

let compressed_bytes = writer.finish()?;
Source

pub fn delimiter(self, delim: u8) -> Self

Set custom delimiter (builder pattern)

Source

pub fn quote_char(self, quote: u8) -> Self

Set custom quote character (builder pattern)

Source

pub fn write_row<I, S>(&mut self, data: I) -> Result<()>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Write a row of strings

§Example
use excelstream::HttpCsvWriter;

let mut writer = HttpCsvWriter::new();
writer.write_row(&["Name", "Age", "City"])?;
writer.write_row(&["Alice", "30", "NYC"])?;
Source

pub fn write_row_typed(&mut self, cells: &[CellValue]) -> Result<()>

Write a row of typed values

§Example
use excelstream::{HttpCsvWriter, CellValue};

let mut writer = HttpCsvWriter::new();
writer.write_row_typed(&[
    CellValue::String("Alice".to_string()),
    CellValue::Int(30),
    CellValue::Float(75.5),
])?;
Source

pub fn row_count(&self) -> u64

Get the number of rows written

Source

pub fn finish(self) -> Result<Vec<u8>>

Finish writing and return the CSV bytes

This consumes the writer and returns the complete CSV file as bytes.

§Example
use excelstream::HttpCsvWriter;

let mut writer = HttpCsvWriter::new();
writer.write_row(&["Name", "Age"])?;
writer.write_row(&["Alice", "30"])?;

let csv_bytes = writer.finish()?;
// Now send csv_bytes as HTTP response

Trait Implementations§

Source§

impl Default for HttpCsvWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.