pub fn from_csv_reader_with_config<R: Read>(
reader: R,
type_name: &str,
schema: &[&str],
config: FromCsvConfig,
) -> Result<Document>Expand description
Parse CSV from a reader into a HEDL document with custom configuration.
This is the most flexible CSV parsing function, supporting both custom I/O sources and custom parsing configuration.
§Arguments
reader- Any type implementingReadtype_name- The HEDL type name for rowsschema- Column names excluding the ‘id’ columnconfig- Configuration controlling all parsing behavior
§Examples
§Large File with Custom Limit
use hedl_csv::{from_csv_reader_with_config, FromCsvConfig};
use std::fs::File;
let file = File::open("large_dataset.csv").unwrap();
let config = FromCsvConfig {
max_rows: 50_000_000, // 50M rows for high-memory server
..Default::default()
};
let doc = from_csv_reader_with_config(file, "Record", &["value"], config).unwrap();§TSV from Network Stream
use hedl_csv::{from_csv_reader_with_config, FromCsvConfig};
use std::net::TcpStream;
let stream = TcpStream::connect("example.com:8080").unwrap();
let config = FromCsvConfig {
delimiter: b'\t',
..Default::default()
};
let doc = from_csv_reader_with_config(stream, "Data", &["col1", "col2"], config).unwrap();§Implementation Details
The function performs the following steps:
- Creates a CSV reader with the specified configuration
- Initializes a new HEDL document with version (1, 0)
- Constructs the full schema (ID column + provided columns)
- Registers the struct type in the document
- Iterates through CSV records:
- Checks row count against
max_rowssecurity limit - Parses each field using type inference
- Validates field count matches schema
- Creates
Nodeinstances and adds to matrix list
- Checks row count against
- Inserts the completed matrix list into the document
§See Also
from_csv_with_config- For parsing CSV stringsFromCsvConfig- Configuration options documentation