From 1af9352a8fa4b46650963dde9efc732f1d65822f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Sun, 22 Oct 2023 14:18:28 +0200 Subject: [PATCH] Make run_app in inspector take a slice instead of path (#206) This is a much more ergonomic api when creating a custom loader, as the flatbuffer data might be offset, compressed, or otherwise not loadable from a path --- crates/planus-cli/src/app/view.rs | 3 ++- crates/planus-inspector/src/app.rs | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/planus-cli/src/app/view.rs b/crates/planus-cli/src/app/view.rs index d80932d3..b4ab9cf4 100644 --- a/crates/planus-cli/src/app/view.rs +++ b/crates/planus-cli/src/app/view.rs @@ -17,6 +17,7 @@ pub struct Command { impl Command { pub fn run(self, _options: super::AppOptions) -> Result { - planus_inspector::app::run_app(&self.schema_file, &self.root_type, &self.data_file) + let buffer = std::fs::read(&self.data_file)?; + planus_inspector::app::run_app(&self.schema_file, &self.root_type, &buffer) } } diff --git a/crates/planus-inspector/src/app.rs b/crates/planus-inspector/src/app.rs index b1afb393..a8ebfb22 100644 --- a/crates/planus-inspector/src/app.rs +++ b/crates/planus-inspector/src/app.rs @@ -13,9 +13,7 @@ use tui::{backend::CrosstermBackend, Terminal}; use crate::{run_inspector, Inspector}; -pub fn run_app(schema_file: &Path, root_type: &str, data_file: &Path) -> Result { - let buffer = std::fs::read(data_file)?; - +pub fn run_app(schema_file: &Path, root_type: &str, buffer: &[u8]) -> Result { let Some(declarations) = translate_files(&[schema_file]) else { return Ok(ExitCode::FAILURE); }; @@ -66,7 +64,7 @@ pub fn run_app(schema_file: &Path, root_type: &str, data_file: &Path) -> Result< let inspector = Inspector::new( planus_buffer_inspection::InspectableFlatbuffer { declarations: &declarations, - buffer: &buffer, + buffer, }, DeclarationIndex(root_table_index), );