9 releases (4 breaking)

0.5.0 Dec 14, 2023
0.4.1 Dec 6, 2023
0.3.1 Dec 5, 2023
0.2.2 Dec 5, 2023
0.1.0 Dec 1, 2023

#1008 in Encoding

Download history 86/week @ 2024-07-22 6/week @ 2024-09-23

120 downloads per month

MIT license

55KB
1.5K SLoC

Network Rail CIF Parser

Usage

Reading the schedule

You can parse a CIF file into a Schedule database with the following code:

use nr_cif::prelude::*;

use std::fs::File;

let f = File::open("full-or-partial.cif").expect("cannot read file");
let cif_result = parse_cif(f);
match cif_result {
    Ok(file) => {
        let mut schedule = ScheduleDatabase::new();
        let errors = schedule.apply_file(&file);
        log::info!("Complete.\n{schedule:#?}\nErrors: {errors:?}");
    },
    Err(e) => panic!("{e}"),
}

Note: This does not always expose every field from the records.

Parsing data in a raw manner

You can parse a CIF file into a records array with the following code:

use nr_cif::prelude::*;

use std::fs::File;

let f = File::open("full-or-partial.cif").expect("cannot read file");
let cif_result = parse_cif(f);
match cif_result {
    Ok(file) => {
        for record in file.records() {
            // do something with each record
        }
    },
    Err(e) => panic!("{e}"),
}

This can then be processed further manually.

Features

Feature Purpose
serde Enable serialization and deserialization on the objects.
panic-on-first-error Panic if a parsing error is discovered. Mostly for testing.

Dependencies

~1.4–2.2MB
~41K SLoC