Skip to content

A fast, helpful, and open-source document parser

fmt and clippy

Logan Markewich8724391d83a3
diff --git a/crates/liteparse-napi/build.rs b/crates/liteparse-napi/build.rs
index 2f8c9fc..6cd8f4d 100644
--- a/crates/liteparse-napi/build.rs
+++ b/crates/liteparse-napi/build.rs
@@ -25,9 +25,9 @@ fn main() {
// Also add the build-time pdfium path so local dev builds work without
// copying libpdfium manually.
- if let Ok(lib_path) = env::var("DEP_PDFIUM_LIB_PATH") {
- if target_os == "macos" || target_os == "linux" {
- println!("cargo:rustc-link-arg=-Wl,-rpath,{lib_path}");
- }
+ if let Ok(lib_path) = env::var("DEP_PDFIUM_LIB_PATH")
+ && (target_os == "macos" || target_os == "linux")
+ {
+ println!("cargo:rustc-link-arg=-Wl,-rpath,{lib_path}");
}
}
diff --git a/crates/liteparse-napi/src/types.rs b/crates/liteparse-napi/src/types.rs
index ef9e044..d25677e 100644
--- a/crates/liteparse-napi/src/types.rs
+++ b/crates/liteparse-napi/src/types.rs
@@ -182,11 +182,7 @@ pub struct JsScreenshotResult {
impl JsParseResult {
pub fn from_rust(result: &ParseResult, _config: &LiteParseConfig) -> Self {
Self {
- pages: result
- .pages
- .iter()
- .map(JsParsedPage::from_rust)
- .collect(),
+ pages: result.pages.iter().map(JsParsedPage::from_rust).collect(),
text: result.text.clone(),
}
}
diff --git a/crates/liteparse-python/build.rs b/crates/liteparse-python/build.rs
index ee9ce6e..decf075 100644
--- a/crates/liteparse-python/build.rs
+++ b/crates/liteparse-python/build.rs
@@ -2,7 +2,8 @@ use std::env;
fn main() {
// Get the pdfium lib path from the pdfium-sys link metadata
- let lib_path = env::var("DEP_PDFIUM_LIB_PATH").expect("DEP_PDFIUM_LIB_PATH not set (from pdfium-sys)");
+ let lib_path =
+ env::var("DEP_PDFIUM_LIB_PATH").expect("DEP_PDFIUM_LIB_PATH not set (from pdfium-sys)");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
diff --git a/crates/liteparse-python/src/cli.rs b/crates/liteparse-python/src/cli.rs
index 7ee37d7..0deacdc 100644
--- a/crates/liteparse-python/src/cli.rs
+++ b/crates/liteparse-python/src/cli.rs
@@ -177,7 +177,10 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
let output_path = format!("{}/page_{}.png", cmd.output_dir, page_number);
render::screenshot(&cmd.file, page_number, cmd.dpi, &output_path)?;
if !cmd.quiet {
- eprintln!("[liteparse] screenshot page {} → {}", page_number, output_path);
+ eprintln!(
+ "[liteparse] screenshot page {} → {}",
+ page_number, output_path
+ );
}
}
}
@@ -186,7 +189,11 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
let format = parse_output_format(&cmd.format)?;
let ext_filter = cmd.extension.as_ref().map(|e| {
let e = e.to_lowercase();
- if e.starts_with('.') { e } else { format!(".{}", e) }
+ if e.starts_with('.') {
+ e
+ } else {
+ format!(".{}", e)
+ }
});
let config = LiteParseConfig {
@@ -204,7 +211,11 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
};
let lp = LiteParse::new(config);
- let out_ext = if format == OutputFormat::Json { "json" } else { "txt" };
+ let out_ext = if format == OutputFormat::Json {
+ "json"
+ } else {
+ "txt"
+ };
std::fs::create_dir_all(&cmd.output_dir)?;
let files = collect_files(&cmd.input_dir, cmd.recursive, ext_filter.as_deref())?;
@@ -238,16 +249,30 @@ pub fn run_cli(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
success += 1;
if !cmd.quiet {
let elapsed = t0.elapsed().as_secs_f64() * 1000.0;
- eprintln!("[liteparse] {} → {} ({:.1}ms)", file_path, out_path.display(), elapsed);
+ eprintln!(
+ "[liteparse] {} → {} ({:.1}ms)",
+ file_path,
+ out_path.display(),
+ elapsed
+ );
}
}
- Err(e) => { eprintln!("[liteparse] error formatting {}: {}", file_path, e); errors += 1; }
+ Err(e) => {
+ eprintln!("[liteparse] error formatting {}: {}", file_path, e);
+ errors += 1;
+ }
},
- Err(e) => { eprintln!("[liteparse] error parsing {}: {}", file_path, e); errors += 1; }
+ Err(e) => {
+ eprintln!("[liteparse] error parsing {}: {}", file_path, e);
+ errors += 1;
+ }
}
}
- eprintln!("[liteparse] batch complete: {} succeeded, {} failed", success, errors);
+ eprintln!(
+ "[liteparse] batch complete: {} succeeded, {} failed",
+ success, errors
+ );
if errors > 0 {
std::process::exit(1);
}
diff --git a/crates/liteparse-python/src/lib.rs b/crates/liteparse-python/src/lib.rs
index c633d7e..3307693 100644
--- a/crates/liteparse-python/src/lib.rs
+++ b/crates/liteparse-python/src/lib.rs
@@ -117,7 +117,11 @@ impl PyParseResult {
}
fn __repr__(&self) -> String {
- format!("ParseResult(pages={}, text_len={})", self.pages.len(), self.text.len())
+ format!(
+ "ParseResult(pages={}, text_len={})",
+ self.pages.len(),
+ self.text.len()
+ )
}
}
@@ -334,12 +338,12 @@ impl LiteParse {
"page {page_num} out of range (document has {page_count} pages)"
)));
}
- let page = document.page((page_num - 1) as i32).map_err(|e| {
- PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string())
- })?;
- let bitmap = page.render(dpi).map_err(|e| {
- PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string())
- })?;
+ let page = document
+ .page((page_num - 1) as i32)
+ .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?;
+ let bitmap = page
+ .render(dpi)
+ .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?;
let width = bitmap.width() as u32;
let height = bitmap.height() as u32;
@@ -390,8 +394,7 @@ impl LiteParse {
/// Run the `lit` CLI with the given arguments.
#[pyfunction]
fn run_cli(args: Vec<String>) -> PyResult<()> {
- cli::run_cli(args)
- .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
+ cli::run_cli(args).map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pymodule]
diff --git a/crates/liteparse/src/conversion.rs b/crates/liteparse/src/conversion.rs
index 492976d..d75e023 100644
--- a/crates/liteparse/src/conversion.rs
+++ b/crates/liteparse/src/conversion.rs
@@ -226,7 +226,7 @@ pub async fn is_path_executable(file_path: &str) -> bool {
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
- return meta.permissions().mode() & 0o111 != 0;
+ meta.permissions().mode() & 0o111 != 0
}
#[cfg(windows)]
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index e42363c..697ac45 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -37,8 +37,8 @@ impl LiteParse {
let pdf_input = if conversion::is_pdf(input) {
PdfInput::Path(input.to_string())
} else {
- let converted = conversion::convert_to_pdf(input, self.config.password.as_deref())
- .await?;
+ let converted =
+ conversion::convert_to_pdf(input, self.config.password.as_deref()).await?;
PdfInput::Path(converted.pdf_path)
};
@@ -49,7 +49,10 @@ impl LiteParse {
///
/// Use `PdfInput::Path` for files on disk or `PdfInput::Bytes` for
/// in-memory PDF data (e.g. from a network response or Node.js Buffer).
- pub async fn parse_input(&self, input: PdfInput) -> Result<ParseResult, Box<dyn std::error::Error>> {
+ pub async fn parse_input(
+ &self,
+ input: PdfInput,
+ ) -> Result<ParseResult, Box<dyn std::error::Error>> {
let log = |msg: &str| {
if !self.config.quiet {
eprintln!("{}", msg);