pub trait LengthResolver {
// Required method
fn resolve_length(&mut self, length_ref: ObjectId) -> Result<i64, PdfError>;
}Expand description
Caller-supplied hook that resolves an indirect /Length reference
on a stream dictionary to the underlying integer.
ISO 32000-1 §7.3.10 Example 3 makes indirect /Length normative on
stream objects: a one-pass writer that doesn’t know the encoded
stream size up front emits << /Length 8 0 R >> and writes the
length-carrying integer object after the stream. A reader walking
such a PDF needs the xref table to fetch the integer.
The trait receives the ObjectId from the reference and is
expected to return the resolved integer (or a PdfError when the
target is missing / not an integer / a cycle is detected). Using a
trait (rather than a free FnMut) sidesteps the lifetime
gymnastics needed to thread an Option<&mut dyn FnMut> through
multiple recursive parse helpers — implementers just write a tiny
struct holding the borrowed state they need.
When the resolver is the unit no-op NoLengthResolver (the
Parser::parse_indirect / Parser::parse_object entry
points), an indirect /Length is rejected — that path is reserved
for xref-stream parsing, where the xref isn’t built yet and the
spec (§7.5.8) effectively requires the direct-integer form anyway.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl LengthResolver for NoLengthResolver
impl<F> LengthResolver for F
Blanket impl so closures with the same signature work as
LengthResolvers without writing a struct.