Skip to main content

spdf_types/
input.rs

1//! Accepted inputs for [`crate::ParseConfig`]-driven operations.
2
3use std::path::PathBuf;
4
5/// A document source: either a file path or raw bytes.
6///
7/// Mirrors `LiteParseInput` in the TypeScript codebase.
8#[derive(Debug, Clone)]
9pub enum ParseInput {
10    /// Path to a file on disk.
11    Path(PathBuf),
12    /// In-memory bytes. PDFs go straight to the parser with zero disk I/O;
13    /// non-PDF bytes are written to a temp file for format conversion.
14    Bytes(Vec<u8>),
15}
16
17impl From<PathBuf> for ParseInput {
18    fn from(p: PathBuf) -> Self {
19        ParseInput::Path(p)
20    }
21}
22
23impl From<&std::path::Path> for ParseInput {
24    fn from(p: &std::path::Path) -> Self {
25        ParseInput::Path(p.to_path_buf())
26    }
27}
28
29impl From<String> for ParseInput {
30    fn from(s: String) -> Self {
31        ParseInput::Path(PathBuf::from(s))
32    }
33}
34
35impl From<&str> for ParseInput {
36    fn from(s: &str) -> Self {
37        ParseInput::Path(PathBuf::from(s))
38    }
39}
40
41impl From<Vec<u8>> for ParseInput {
42    fn from(b: Vec<u8>) -> Self {
43        ParseInput::Bytes(b)
44    }
45}