to_csv

Crates.ioto_csv
lib.rsto_csv
version1.0.1
created_at2025-06-03 02:54:42.27199+00
updated_at2025-06-05 14:09:52.237115+00
descriptionLightweight and easy exports to CSV
homepage
repositoryhttps://github.com/JohnBCoding/to_csv
max_upload_size
id1698610
size6,471
JohnBCoding (JohnBCoding)

documentation

https://docs.rs/to_csv

README

This library provides a lightweight way to export data to the CSV format via trait implementation.

crates.io docs.rs

Example

[dependencies]
to_csv = "1.0"
struct TypeA {
    name: String,
    value: String,
    date: String,
}

impl CSV for TypeA {
    fn headers(&self) -> String {
        format!("{},{},{}", "Data Name", "Amount", "Date",)
    }
    
    fn row(&self) -> String {
        format!(
            "{},{},{}",
            self.name,
            self.value,
            self.date,
        )
    }
}

fn main() {
    let entries = vec![TypeA {name: "Test Data".to_string(), value: "10".to_string(), date: "6/3/2025".to_string()}]
    let _ = to_csv_file("csv_file.csv", &entries);
}

Result

Data Name,Amount,Date,
Test Data,10,6/3/2025,
Commit count: 11

cargo fmt