Skip to main content

to_csv

Function to_csv 

Source
pub fn to_csv(
    file: &str,
    output: Option<&str>,
    include_headers: bool,
) -> Result<(), CliError>
Expand description

Convert a HEDL file to CSV format.

Parses a HEDL file and converts it to CSV format. Expects the HEDL file to contain a matrix list that can be represented as a table.

§Arguments

  • file - Path to the HEDL file to convert
  • output - Optional output file path. If None, writes to stdout
  • include_headers - If true, includes header row with column names (default: true)

§Returns

Returns Ok(()) on success.

§Errors

Returns Err if:

  • The file cannot be read
  • The file contains syntax errors
  • The HEDL structure is not compatible with CSV (e.g., nested structures)
  • CSV conversion fails
  • Output writing fails

§Examples

use hedl_cli::commands::to_csv;

// Convert to CSV on stdout with headers
to_csv("data.hedl", None, true)?;

// Convert to CSV without headers (useful for appending)
to_csv("data.hedl", Some("output.csv"), false)?;