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 bodyImplementations§
Source§impl HttpCsvWriter
impl HttpCsvWriter
Sourcepub fn new() -> Self
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()?;Sourcepub fn with_compression(compression_level: u32) -> Self
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()?;Sourcepub fn quote_char(self, quote: u8) -> Self
pub fn quote_char(self, quote: u8) -> Self
Set custom quote character (builder pattern)
Sourcepub fn write_row<I, S>(&mut self, data: I) -> Result<()>
pub fn write_row<I, S>(&mut self, data: I) -> Result<()>
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"])?;Sourcepub fn write_row_typed(&mut self, cells: &[CellValue]) -> Result<()>
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),
])?;Sourcepub fn finish(self) -> Result<Vec<u8>>
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 responseTrait Implementations§
Auto Trait Implementations§
impl Freeze for HttpCsvWriter
impl !RefUnwindSafe for HttpCsvWriter
impl !Send for HttpCsvWriter
impl !Sync for HttpCsvWriter
impl Unpin for HttpCsvWriter
impl !UnwindSafe for HttpCsvWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more