Skip to main content

to_file

Function to_file 

Source
pub fn to_file<H: HashTable, P: AsRef<Path>>(
    jmap: &JMapInfo<H>,
    path: P,
    options: &IoOptions,
) -> Result<()>
Expand description

Write a JMapInfo to a file

§Arguments

  • jmap - The JMapInfo instance to write to the file
  • path - The path to the file where the BCSV data should be written
  • options - Options for endianness and string encoding

§Type

  • H - The type of hash table used by the JMapInfo, which must implement the HashTable trait
  • P - A type that can be converted to a Path reference, such as &str or String

§Returns

Ok(()) if the file was successfully written, or an error if the file cannot be created or written to

Examples found in repository?
examples/write_bcsv.rs (line 18)
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 csv_path = Path::new("assets/examples/scenariodata.csv");
11    let jmap = from_csv(hash_table, csv_path, None)?;
12
13    println!("CSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    to_file(&jmap, "test_output.bcsv", &IoOptions::default())?;
19    println!("\nExported to test_output.bcsv");
20
21    Ok(())
22}