Skip to main content

NameTree

Struct NameTree 

Source
pub struct NameTree { /* private fields */ }
Expand description

Read and modify a PDF name tree (a /Names-style sorted key/value index).

Name keys are supplied as UTF-8 bytes. Both byte slices and strings are accepted through [AsRef<[u8]>].

qpdf correspondence: NNTreeImpl (libqpdf/NNTree.cc) constructed with NameTreeDetails (libqpdf/QPDFNameTreeObjectHelper.cc).

Implementations§

Source§

impl NameTree

Source

pub fn new(root: ObjectHandle, auto_repair: bool) -> Self

Wrap an existing name-tree root handle.

The first PDF passed to an operation claims the handle’s document boundary; subsequent operations reject handles from another PDF.

Source

pub fn new_empty<R: Read + Seek>( pdf: &mut Pdf<R>, auto_repair: bool, ) -> Result<Self>

Create an empty name tree with an indirect root.

§Errors

Returns an error when the PDF object-number space is exhausted.

Source

pub fn get_object_handle(&self) -> ObjectHandle

Return the live root handle, matching qpdf’s getObjectHandle.

Source

pub fn end(&self) -> NameTreeCursor

Return an invalid cursor representing the position past the tree.

Source

pub fn begin<R: Read + Seek>( &mut self, pdf: &mut Pdf<R>, ) -> Result<NameTreeCursor>

Return a cursor positioned at the first entry.

§Errors

Returns an error when the tree cannot be resolved or traversed.

Source

pub fn last<R: Read + Seek>( &mut self, pdf: &mut Pdf<R>, ) -> Result<NameTreeCursor>

Return a cursor positioned at the last entry.

§Errors

Returns an error when the tree cannot be resolved or traversed.

Source

pub fn find<R: Read + Seek, K: AsRef<[u8]>>( &mut self, pdf: &mut Pdf<R>, key: K, return_previous_if_missing: bool, ) -> Result<NameTreeCursor>

Find key, optionally returning the closest lower entry.

§Errors

Returns an error when the tree cannot be resolved or searched.

Source

pub fn insert<R: Read + Seek, K: AsRef<[u8]>>( &mut self, pdf: &mut Pdf<R>, key: K, value: ObjectHandle, ) -> Result<NameTreeCursor>

Insert or replace an entry and return a cursor positioned at it.

§Errors

Returns an error when the tree cannot be resolved or mutated.

Source

pub fn has_name<R: Read + Seek, K: AsRef<[u8]>>( &mut self, pdf: &mut Pdf<R>, key: K, ) -> Result<bool>

Return whether the tree contains an explicit entry for key.

§Errors

Returns an error when the tree cannot be resolved or searched.

Source

pub fn find_object<R: Read + Seek, K: AsRef<[u8]>>( &mut self, pdf: &mut Pdf<R>, key: K, ) -> Result<Option<ObjectHandle>>

Find the value stored at key.

§Errors

Returns an error when the tree cannot be resolved or searched.

Source

pub fn remove<R: Read + Seek, K: AsRef<[u8]>>( &mut self, pdf: &mut Pdf<R>, key: K, ) -> Result<Option<ObjectHandle>>

Remove the entry at key, returning its former value.

§Errors

Returns an error when the tree cannot be resolved or mutated.

Source

pub fn as_map<R: Read + Seek>( &mut self, pdf: &mut Pdf<R>, ) -> Result<BTreeMap<Vec<u8>, ObjectHandle>>

Materialize the tree as a sorted map.

§Errors

Returns an error when the tree cannot be resolved or traversed.

Source

pub fn set_split_threshold(&mut self, threshold: usize)

Set the node split threshold.

This exists for qpdf-compatible tests; production callers normally retain the default threshold of 32.

Source

pub fn set_max_depth(&mut self, max_depth: usize)

Bound /Kids chain traversal to max_depth levels.

Unbounded by default; a caller reading an untrusted document should set this (e.g. to DEFAULT_MAX_TREE_DEPTH) to reject a pathologically deep tree with crate::Error::Unsupported instead of recursing without bound.

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> 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, 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.