pub fn to_csv<H: HashTable, P: AsRef<Path>>(
jmap: &JMapInfo<H>,
path: P,
header_delimiter: Option<char>,
) -> Result<()>Expand description
Write a JMapInfo to a CSV file
The CSV format uses a header row where each column is formatted as:
FieldName:Type:DefaultValue
§Arguments
jmap- The JMapInfo to export to CSVpath- The path to the CSV file to writeheader_delimiter- Optional character that separates field name, type, and default value in the header. Default is ‘:’
§Returns
Ok(()) if the export was successful, or an error if the file could not be written
Examples found in repository?
examples/read_bcsv.rs (line 25)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let lookup_path = Path::new("assets/strings_SMG.txt");
8 let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10 let bcsv_path = Path::new("assets/examples/scenariodata.bcsv");
11 let jmap = from_file(hash_table, bcsv_path, &IoOptions::default())?;
12
13 println!("BCSV Info");
14 println!("Entries: {}", jmap.len());
15 println!("Fields: {}", jmap.num_fields());
16 println!();
17
18 println!("Fields");
19 for field in jmap.fields() {
20 let name = jmap.field_name(field.hash);
21 println!("+0x{:X} - {} - {}", field.offset, name, field.field_type);
22 }
23 println!();
24
25 to_csv(&jmap, "test_output.csv", None)?;
26 println!("\nExported to test_output.csv");
27
28 Ok(())
29}