Skip to main content

from_csv_reader

Function from_csv_reader 

Source
pub fn from_csv_reader<R: Read>(
    reader: R,
    type_name: &str,
    schema: &[&str],
) -> Result<Document>
Expand description

Parse CSV from a reader into a HEDL document with default configuration.

This function is useful for processing CSV files or network streams without loading the entire content into memory first.

§Arguments

  • reader - Any type implementing Read (e.g., File, TcpStream, &[u8])
  • type_name - The HEDL type name for rows
  • schema - Column names excluding the ‘id’ column

§Examples

§Reading from a File

use hedl_csv::from_csv_reader;
use std::fs::File;

let file = File::open("data.csv").unwrap();
let doc = from_csv_reader(file, "Person", &["name", "age"]).unwrap();

§Reading from a Byte Slice

use hedl_csv::from_csv_reader;

let csv_bytes = b"id,name\n1,Alice";
let doc = from_csv_reader(&csv_bytes[..], "Person", &["name"]).unwrap();

§Reading from Standard Input

use hedl_csv::from_csv_reader;
use std::io;

let stdin = io::stdin();
let doc = from_csv_reader(stdin.lock(), "Record", &["field1", "field2"]).unwrap();

§Performance

This function uses streaming I/O to minimize memory usage. The CSV data is processed row-by-row without buffering the entire file.

§See Also

  • from_csv_reader_with_config - For custom delimiters and limits
  • from_csv - For parsing CSV strings