Skip to main content

Provenance

Enum Provenance 

Source
#[non_exhaustive]
pub enum Provenance { File(ByteSpan), RecoveredFile(ByteSpan), ObjectStream { container: ObjId, index: u32, }, }
Expand description

Where an indirect object’s definition physically lives in the loaded file — the provenance discriminator the minimal-diff writer needs (ARCHITECTURE.md §5; decision 001 §6.1 item 1).

§Why this is an enum and not a ByteSpan

§5’s contract — “an object pdfcer did not logically modify re-emits its source bytes verbatim, or is omitted entirely” — is only expressible for an object defined at file level as N G obj … endobj. A PDF 1.5 object compressed inside an object stream (§7.5.7) has no byte range of its own in the file at all: its bytes exist only inside its container’s encoded stream data, interleaved with the other objects of that container, and are not even recoverable without running the container’s filter chain.

Modelling that as “a span that happens to be wrong/absent” would be a lie the writer could not detect. Making it a type-level distinction forces every future save path to decide consciously what a compressed object means for it:

  • Incremental save, object untouched — emit nothing. The container object is itself span-backed and untouched, so the whole prior revision stays byte-identical. No decision needed.
  • Incremental save, object modified — the object cannot be patched in place; the writer must either re-emit it as a new file-level object in the update section (legal: an object may move out of an object stream between revisions) or write a whole new container. Both are correct; the choice is the writer’s, and it must be made knowingly.
  • Full rewrite — re-serialize from values; there is nothing verbatim to preserve.

The ObjectStream variant carries the container id and the index within it precisely so the writer has the facts to make that choice without re-deriving them from the xref.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

File(ByteSpan)

Defined at file level. The span covers the complete definition — from the first byte of the object number through the last byte of endobj — so an untouched object re-emits (or, in incremental save, retains) exactly its source bytes.

§

RecoveredFile(ByteSpan)

Defined at file level at this span, but the retained bytes are internally inconsistent and therefore must NOT be re-emitted verbatim — the parsed value is authoritative, not the source bytes.

Set in exactly one situation: cross-reference recovery re-derived a stream’s extent from its endstream keyword because the stored /Length was unusable (StreamLengthPolicy::RecoverFromEndstream). The span’s bytes then say one length while the parsed Stream::data_span says another, and copying them through would make pdfcer write out the very inconsistency it just recovered from — producing a file pdfcer itself would refuse to reload. The writer re-serializes instead, which regenerates /Length from the actual data (writer::serialize’s “/Length is always recomputed, never trusted”).

This is a third state rather than a flag on File for the same reason ObjectStream is: it forces every save path to decide consciously what it means, instead of leaving a “span that happens to be untrustworthy” the writer cannot detect. file_span still returns the span — the bytes are genuinely there, and a consumer that wants to show the definition’s location (the CLI’s object listing) is still right to ask. Only re-emission is affected.

§

ObjectStream

Compressed inside an object stream (§7.5.7); reached through a type-2 cross-reference entry (§7.5.8.3 Table 18). There is no file-level span — see the type docs.

Fields

§container: ObjId

The object stream object that holds this object. Its own generation is always 0 (§7.5.7).

§index: u32

0-based index of this object within the container’s pair table (the type-2 entry’s field 3).

Implementations§

Source§

impl Provenance

Source

pub const fn file_span(self) -> Option<ByteSpan>

The object’s verbatim byte range in the retained source buffer, or None for a compressed object (which has none).

This is the accessor the writer uses; returning Option rather than a sentinel is the whole point of the enum (type docs).

Source

pub const fn is_verbatim_safe(self) -> bool

Whether this object’s retained bytes may be copied through to a saved file verbatim.

True only for File. A RecoveredFile object has bytes but they contradict the parsed value, and an ObjectStream object has no file-level bytes at all — both must be re-serialized from values.

Exists so the writer asks the question it actually means. Testing file_span().is_some() would silently start copying self-contradictory bytes the day the third variant appeared, which is precisely the “span that happens to be wrong” failure mode this enum was designed to make impossible.

Source

pub const fn container(self) -> Option<ObjId>

The containing object stream, or None for a file-level object.

Trait Implementations§

Source§

impl Clone for Provenance

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Provenance

Source§

impl Debug for Provenance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Provenance

Source§

impl PartialEq for Provenance

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Provenance

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.