Skip to main content

ResourceManager

Struct ResourceManager 

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

Resource manager for efficient PDF object caching.

The ResourceManager provides centralized caching of PDF objects to avoid repeated parsing overhead. It is owned exclusively by a PdfDocument and uses RefCell for interior mutability, so cache writes can occur through a shared borrow of the document.

§Caching Strategy

  • Objects are cached on first access
  • Cache persists for the lifetime of the document
  • Manual cache clearing is supported for memory management

§Example

use oxidize_pdf::parser::document::ResourceManager;

let resources = ResourceManager::new();

// Objects are cached automatically when accessed through PdfDocument
// Manual cache management:
resources.clear_cache(); // Free memory when needed

Implementations§

Source§

impl ResourceManager

Source

pub fn new() -> Self

Create a new resource manager

Source

pub fn get_cached(&self, obj_ref: (u32, u16)) -> Option<PdfObject>

Get an object from cache if available.

§Arguments
  • obj_ref - Object reference (object_number, generation_number)
§Returns

Cloned object if cached, None otherwise.

§Example
if let Some(obj) = resources.get_cached((10, 0)) {
    println!("Object 10 0 R found in cache");
}
Source

pub fn cache_object(&self, obj_ref: (u32, u16), obj: PdfObject)

Cache an object for future access.

§Arguments
  • obj_ref - Object reference (object_number, generation_number)
  • obj - The PDF object to cache
§Example
resources.cache_object((10, 0), PdfObject::Integer(42));
Source

pub fn clear_cache(&self)

Clear all cached objects to free memory.

Use this when processing large documents to manage memory usage.

§Example
// After processing many pages
resources.clear_cache();
println!("Cache cleared to free memory");

Trait Implementations§

Source§

impl Default for ResourceManager

Source§

fn default() -> Self

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

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more