-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce string allocations by using a writer pattern
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//----------------------------------------------------------------------------- | ||
// Module a2l_reader | ||
// Simplified A2L reader for integration testing | ||
// Uses a2lfile crate to load A2L file | ||
|
||
#![allow(dead_code)] | ||
|
||
#[allow(unused_imports)] | ||
use log::{debug, error, info, trace, warn}; | ||
|
||
use a2lfile::A2lError; | ||
|
||
pub fn a2l_load(filename: &str) -> Result<a2lfile::A2lFile, a2lfile::A2lError> { | ||
trace!("Load A2L file {}", filename); | ||
let input_filename = &std::ffi::OsString::from(filename); | ||
let mut logmsgs = Vec::<A2lError>::new(); | ||
let res = a2lfile::load(input_filename, None, &mut logmsgs, true); | ||
for log_msg in logmsgs { | ||
warn!("A2l Loader: {}", log_msg); | ||
} | ||
match res { | ||
Ok(a2l_file) => { | ||
// Perform a consistency check | ||
let mut logmsgs = Vec::<String>::new(); | ||
a2l_file.check(&mut logmsgs); | ||
for log_msg in logmsgs { | ||
warn!("A2l Checker: {}", log_msg); | ||
} | ||
Ok(a2l_file) | ||
} | ||
|
||
Err(e) => { | ||
error!("a2lfile::load failed: {:?}", e); | ||
Err(e) | ||
} | ||
} | ||
} |