Skip to main content

from_file

Function from_file 

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

Read a JMapInfo from a file

§Arguments

  • hash_table - The hash table to use for field name lookups
  • path - The path to the BCSV file to read
  • options - Options for endianness and string encoding

§Type

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

§Returns

A JMapInfo instance populated with the data from the file, or an error if the file cannot be read or parsed

Examples found in repository?
examples/read_bcsv.rs (line 11)
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}