Skip to main content

Crate pdfrum_common

Crate pdfrum_common 

Source
Expand description

§pdfrum-common

The vocabulary every other crate in the workspace shares, and nothing else: no parsing, no PDF objects, no I/O. Four ideas — the damage channel, the ceilings, the version header, and a zero-based page index — plus kurbo re-exported so geometry is one type across the workspace rather than one per crate.

use pdfrum_common::{DiagKind, Diagnostics, Limits, Severity};

let mut diags = Diagnostics::default();
diags.record(Severity::Recovered, DiagKind::XrefRebuilt, Some(1234));
assert_eq!(diags.len(), 1);

assert_eq!(Limits::default().max_object_nesting, 64);

Diagnostics is why Err is rare. A PDF a browser would open is routinely malformed, so damage the reader survived is recorded, not returned: Severity::Recovered is a repair the reader is confident about (a rebuilt xref, a /Length fixed by scanning for endstream), and Severity::Suspicious is “we proceeded, but information was dropped”. An Err means the file could not be opened at all. DiagKind is #[non_exhaustive] and a variant only exists where a crate actually records it — a variant with no recording site reads as a promise the library does not keep.

Limits is the untrusted-input budget, passed by reference down every call chain rather than read from a global, so two documents in one process can be opened under different ceilings. Deadline is the wall-clock half of the same idea and is separately constructible (Deadline::manual) — Instant::now panics on wasm32, where cancellation is the only stop.

Part of pdfrum. #![forbid(unsafe_code)].

MIT OR Apache-2.0

Re-exports§

pub use kurbo;

Structs§

Deadline
When work must stop. Cloning shares the flag: a host keeps one clone to raise and hands the other to Limits.
Diagnostic
One recorded recovery.
Diagnostics
A bounded sink of Diagnostics.
FxHasher
A non-cryptographic hasher: rotate, xor, multiply, per word.
Limits
Caps applied while reading a document. Plain configuration data: pass it down, never store it in a parser struct that also owns state.
PageIndex
A zero-based page index.
PdfVersion
The version digits from a %PDF-M.N header.

Enums§

DiagKind
What was repaired.
LimitExceeded
A caller-set ceiling was hit. The error a render or an open answers when a Limits field that defaults to off was set and exceeded.
Operation
What the engine was doing when a deadline passed — the noun in the message, and the boundary at which the check sits.
Severity
How badly a recorded event bends the file’s meaning.

Functions§

hex_digit
The value of one ASCII hexadecimal digit, either case, and None for any other byte.

Type Aliases§

FxBuildHasher
A BuildHasher for FxHasher, for use as a map’s third type parameter.