diff --git a/examples/by-hand/src/main.rs b/examples/by-hand/src/main.rs index e507d71..8d313ba 100644 --- a/examples/by-hand/src/main.rs +++ b/examples/by-hand/src/main.rs @@ -1,6 +1,6 @@ use std::time::Instant; -use macroquad::{prelude::*, rand, ui::root_ui}; +use macroquad::{prelude::*, ui::root_ui}; #[macroquad::main("by-hand")] async fn main() { diff --git a/examples/configurable/src/main.rs b/examples/configurable/src/main.rs index 818e6fd..6cefb79 100644 --- a/examples/configurable/src/main.rs +++ b/examples/configurable/src/main.rs @@ -533,8 +533,8 @@ fn generate() -> ( ) { let mut g: StableGraph<(String, Orientation), ()> = StableGraph::new(); - let file = std::fs::File::open(env::args().nth(1).expect("missing gfa file argument")).unwrap(); - let entries = parser::parse_source(file).unwrap(); + let entries = + parser::parse_file(env::args().nth(1).expect("missing gfa file argument")).unwrap(); let mut index_map = HashMap::new(); diff --git a/examples/configurable/src/settings.rs b/examples/configurable/src/settings.rs index 5a95730..2105fdc 100644 --- a/examples/configurable/src/settings.rs +++ b/examples/configurable/src/settings.rs @@ -26,14 +26,14 @@ pub struct SettingsInteraction { pub struct SettingsNavigation { pub fit_to_screen_enabled: bool, pub zoom_and_pan_enabled: bool, - pub screen_padding: f32, + // pub screen_padding: f32, pub zoom_speed: f32, } impl Default for SettingsNavigation { fn default() -> Self { Self { - screen_padding: 0.3, + // screen_padding: 0.3, zoom_speed: 0.1, fit_to_screen_enabled: true, zoom_and_pan_enabled: false, diff --git a/examples/egui-graph-viz/src/main.rs b/examples/egui-graph-viz/src/main.rs index a329bf7..04cfea5 100644 --- a/examples/egui-graph-viz/src/main.rs +++ b/examples/egui-graph-viz/src/main.rs @@ -46,8 +46,7 @@ impl App for InteractiveApp { fn generate_graph() -> Graph<(String, Orientation), ()> { let mut g: StableGraph<(String, Orientation), ()> = StableGraph::new(); - let file = std::fs::File::open("../../dataset/example.gfa").unwrap(); - let entries = parser::parse_source(file).unwrap(); + let entries = parser::parse_file("../../dataset/example.gfa").unwrap(); let mut index_map = HashMap::new(); diff --git a/examples/fdg-example/src/main.rs b/examples/fdg-example/src/main.rs index 39cc4df..b70c4c8 100644 --- a/examples/fdg-example/src/main.rs +++ b/examples/fdg-example/src/main.rs @@ -21,8 +21,9 @@ use macroquad::prelude::*; async fn main() { let mut graph = Graph::<(String, Orientation), ()>::new(); - let file = std::fs::File::open(env::args().nth(1).expect("missing gfa file argument")).unwrap(); - let entries = parser::parse_source(file).unwrap(); + let filename = env::args().nth(1).expect("missing gfa file argument"); + + let entries = parser::parse_file(filename).expect("failed to parse file"); let mut index_map = HashMap::new(); diff --git a/examples/graphs-1/src/main.rs b/examples/graphs-1/src/main.rs index a9ae7ba..b24829f 100644 --- a/examples/graphs-1/src/main.rs +++ b/examples/graphs-1/src/main.rs @@ -137,15 +137,7 @@ fn load_graph() -> StableGraph<(String, Point2), ()> { let mut graph = StableGraph::new(); let filename = env::args().nth(1).expect("missing gfa file argument"); - - let file_lines_count = BufReader::new(std::fs::File::open(&filename).expect("file not found")) - .lines() - .progress_with(indicatif::ProgressBar::new_spinner()) - .count() as u64; - - let file = std::fs::File::open(filename).unwrap(); - - let entries = parser::parse_source(file, file_lines_count).unwrap(); + let entries = parser::parse_file(filename).expect("failed to parse file"); let mut index_map = HashMap::new(); diff --git a/src/parser.rs b/src/parser.rs index 67c93e5..a89b96f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Cow, io::{self, BufRead, BufReader, Read}, str::FromStr, thread, @@ -126,6 +127,17 @@ fn parse_walk(line: &str) -> Entry { } } +pub fn parse_file>(file: R) -> io::Result> { + let file_lines_count = BufReader::new(std::fs::File::open(file.as_ref())?) + .lines() + .progress_count(0) + .count() as u64; + + let file = std::fs::File::open(file.as_ref())?; + + parse_source(file, file_lines_count) +} + pub fn parse_source(reader: R, line_count: u64) -> io::Result> { let mut entries = Vec::new(); let mut skipped = Vec::new();