Skip to main content

Dict

Struct Dict 

Source
pub struct Dict(pub Vec<(Name, Object)>);
Expand description

A dictionary (§7.3.7): name-keyed, unordered per spec — but pdfcer preserves the parsed entry order so that re-serializing a modified dictionary perturbs sibling entries as little as possible (smaller diffs; the spec says written order “shall be ignored”, so preserving it is always safe).

Backed by an ordered Vec with linear-scan lookup: PDF dictionaries are small (a handful to a few dozen entries), where a Vec beats a hash map on both speed and memory, and it keeps deterministic order for free.

Tuple Fields§

§0: Vec<(Name, Object)>

Implementations§

Source§

impl Dict

Source

pub const fn new() -> Self

Empty dictionary.

Source

pub fn get(&self, key: &[u8]) -> Option<&Object>

Look up key, applying the §7.3.7/§7.3.9 rule: an entry whose value is null is treated as if absent — this returns None for it. Implemented here, once, so no call site ever needs a second “is it null?” check (see the spec RAG’s API note).

Source

pub fn contains_key(&self, key: &[u8]) -> bool

Whether key is present with a non-null value (same collapse rule as Dict::get).

Source

pub fn len(&self) -> usize

Number of stored entries (including any explicit-null entries — this is the physical count, used by serialization; semantic presence goes through Dict::get).

Source

pub fn is_empty(&self) -> bool

Whether the dictionary stores no entries at all.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Name, &Object)>

Iterate entries in preserved (parsed/inserted) order.

Source

pub fn insert(&mut self, key: Name, value: Object)

Insert or replace key → value, preserving position on replace (append on fresh insert). The write-side primitive the editing Passes build on.

Source

pub fn remove(&mut self, key: &[u8]) -> Option<Object>

Remove key entirely, returning its stored value if there was one.

§Why removal, and not “set it to null”

§7.3.7 makes a null-valued entry semantically identical to an absent one, so insert(key, Object::Null) would be correct. It would also leave a physical entry behind, which means a re-serialized dictionary carries a visible /Title null the operator never asked for, and a later reader cannot tell “pdfcer cleared this” from “the producer wrote an explicit null”. Under the minimal-diff discipline the honest form of clear this field is for the field not to be there.

Removes all entries with this key, not just the first. Duplicate keys are malformed per §7.3.7 (“shall not”) and the parser rejects them, so a parsed dictionary never has any — but a Dict built programmatically could, and leaving a shadowed duplicate behind would make removal look like it did nothing.

Trait Implementations§

Source§

impl Clone for Dict

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 Debug for Dict

Source§

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

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

impl Default for Dict

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Dict

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 Dict

Auto Trait Implementations§

§

impl Forget for Dict

§

impl Freeze for Dict

§

impl RefUnwindSafe for Dict

§

impl Send for Dict

§

impl Sync for Dict

§

impl Unpin for Dict

§

impl UnsafeUnpin for Dict

§

impl UnwindSafe for Dict

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.