Crates.io | nr-cif |
lib.rs | nr-cif |
version | 0.5.0 |
source | src |
created_at | 2023-12-01 17:36:33.12771 |
updated_at | 2023-12-14 01:28:51.826175 |
description | Handle Network Rail CIF files. |
homepage | |
repository | https://github.com/lilopkins/nr-cif-rs |
max_upload_size | |
id | 1055387 |
size | 60,971 |
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.
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.
Feature | Purpose |
---|
serde
| Enable serialization and deserialization on the objects.
panic-on-first-error
| Panic if a parsing error is discovered. Mostly for testing.