csv
16 items · generated by scribe fromstdlib/csv.fd· synced 2026-11-15
Contents
- CsvRow (struct)
- CsvRecord (struct)
- csv_parse (function)
- csv_parse_dialect (function)
- csv_parse_records (function)
- csv_record_get (function)
- csv_quote_field (function)
- csv_quote_field_dialect (function)
- csv_serialize (function)
- csv_serialize_dialect (function)
- csv_row (function)
- csv_field (function)
- csv_row_count (function)
- csv_col_count (function)
- csv_column (function)
CsvRow
One CSV record: a list of string fields.
pub struct CsvRow {Fields:
| Name | Type |
|---|---|
fields | Vec<str> |
Defined at line 19
CsvRecord
A header→value record as produced by csv_parse_records: keys and values are parallel; index-aligned.
pub struct CsvRecord {Fields:
| Name | Type |
|---|---|
keys | Vec<str> |
values | Vec<str> |
Defined at line 25
csv_parse
Parse CSV text into a Vec of CsvRow. A trailing newline does not add a phantom row; “a,b\n\n” keeps the empty second row.
Example: var rows = csv_parse(“name,qty\n”Smith, J”,3\n”); assert_eq(csv_row_count(rows), 2); assert_eq(csv_field(rows, 1, 0), “Smith, J”); assert_eq(csv_field(rows, 1, 1), “3”);
pub fn csv_parse(text: str) -> Vec<CsvRow> {Parameters:
text:str
Returns: Vec<CsvRow>
Defined at line 42
csv_parse_dialect
Full-dialect parse with a custom delim and quote character.
Example: var rows = csv_parse_dialect(“a;b\n1;2”, ’;’, ’”’); assert_eq(csv_field(rows, 1, 1), “2”);
pub fn csv_parse_dialect(text: str, delim: i64, quote: i64) -> Vec<CsvRow> {Parameters:
text:strdelim:i64quote:i64
Returns: Vec<CsvRow>
Defined at line 51
csv_parse_records
Parse with the first line as headers; returns one CsvRecord per data row.
Example: var recs = csv_parse_records(“id,name\n1,Ada\n2,Bob\n”); assert_eq(recs.len(), 2); assert_eq(csv_record_get(recs.get(1), “name”), “Bob”);
pub fn csv_parse_records(text: str) -> Vec<CsvRecord> {Parameters:
text:str
Returns: Vec<CsvRecord>
Defined at line 119
csv_record_get
Look up key in a CsvRecord; "" when absent.
Example: var recs = csv_parse_records(“id,name\n1,Ada\n”); assert_eq(csv_record_get(recs.get(0), “id”), “1”); assert_eq(csv_record_get(recs.get(0), “email”), "");
pub fn csv_record_get(rec: CsvRecord, key: str) -> str {Parameters:
rec:CsvRecordkey:str
Returns: str
Defined at line 153
csv_quote_field
Quote a field if it contains the delimiter, quotes, or newlines.
Example: assert_eq(csv_quote_field(“plain”), “plain”); assert_eq(csv_quote_field(“a,b”), ""a,b""); assert_eq(csv_quote_field(“say “hi""), ""say ""hi"""");
pub fn csv_quote_field(field: str) -> str {Parameters:
field:str
Returns: str
Defined at line 185
csv_quote_field_dialect
Quote a field for a dialect with the given delimiter and quote character.
Example: assert_eq(csv_quote_field_dialect(“a;b”, ’;’, ’”’), ""a;b""); assert_eq(csv_quote_field_dialect(“a,b”, ’;’, ’”’), “a,b”);
pub fn csv_quote_field_dialect(field: str, delim: i64, quote: i64) -> str {Parameters:
field:strdelim:i64quote:i64
Returns: str
Defined at line 194
csv_serialize
Serialize rows back to CSV text with LF line endings.
Example: var rows: Vec
pub fn csv_serialize(rows: Vec<CsvRow>) -> str {Parameters:
rows:Vec<CsvRow>
Returns: str
Defined at line 230
csv_serialize_dialect
Serialize rows with a custom delimiter, LF line endings.
Example: var rows = csv_parse(“a,b\n1,2\n”); assert_eq(csv_serialize_dialect(rows, ‘\t’), “a\tb\n1\t2\n”);
pub fn csv_serialize_dialect(rows: Vec<CsvRow>, delim: i64) -> str {Parameters:
rows:Vec<CsvRow>delim:i64
Returns: str
Defined at line 239
csv_row
Build a CsvRow from a Vec of str.
Example: var f: Vec
pub fn csv_row(fields: Vec<str>) -> CsvRow {Parameters:
fields:Vec<str>
Returns: CsvRow
Defined at line 266
csv_field
Field at (row, col) or "" when out of range.
Example: var rows = csv_parse(“a,b\n”); assert_eq(csv_field(rows, 0, 1), “b”); assert_eq(csv_field(rows, 5, 0), "");
pub fn csv_field(rows: Vec<CsvRow>, r: i64, c: i64) -> str {Parameters:
rows:Vec<CsvRow>r:i64c:i64
Returns: str
Defined at line 280
csv_row_count
Number of parsed rows.
Example: assert_eq(csv_row_count(csv_parse(“a\nb\nc\n”)), 3);
pub fn csv_row_count(rows: Vec<CsvRow>) -> i64 {Parameters:
rows:Vec<CsvRow>
Returns: i64
Defined at line 295
csv_col_count
Column count of row r (0 if out of range).
Example: var rows = csv_parse(“a,b,c\nd\n”); assert_eq(csv_col_count(rows, 0), 3); assert_eq(csv_col_count(rows, 1), 1);
pub fn csv_col_count(rows: Vec<CsvRow>, r: i64) -> i64 {Parameters:
rows:Vec<CsvRow>r:i64
Returns: i64
Defined at line 305
csv_column
Extract column c across all rows (missing cells become "").
Example: var col = csv_column(csv_parse(“a,1\nb,2\n”), 1); assert_eq(col.len(), 2); assert_eq(col.get(1), “2”);
pub fn csv_column(rows: Vec<CsvRow>, c: i64) -> Vec<str> {Parameters:
rows:Vec<CsvRow>c:i64
Returns: Vec<str>
Defined at line 318
Generated by scribe, the Fides documentation generator