Skip to main content

Resolved

Enum Resolved 

Source
pub enum Resolved<'a> {
    Direct(&'a Object),
    Indirect(Arc<Object>),
}
Expand description

The result of resolving: a direct object stays borrowed, an indirect one arrives shared from the store.

Behaves like the Object it holds through Deref, so callers match on it without caring which side it came from.

use pdfrum_object::{Object, Resolved};

let obj = Object::Int(42);
let resolved = Resolved::Direct(&obj);
assert_eq!(resolved.as_int(), Some(42));

Variants§

§

Direct(&'a Object)

The object was already direct; this borrows it in place.

§

Indirect(Arc<Object>)

The object came from the store and is shared with it.

Implementations§

Source§

impl Resolved<'_>

Source

pub fn get(&self) -> &Object

The object, whichever side it came from.

Source

pub fn as_direct(&self) -> Option<&Object>

The object unless it is itself a reference.

This is where Resolve’s one-hop rule is enforced: every typed accessor goes through here, so a reference-to-reference chain reads as absence.

Source

pub fn into_owned(self) -> Object

Take ownership of the object, cloning a borrowed one.

Methods from Deref<Target = Object>§

Source

pub fn as_bool(&self) -> Option<bool>

The boolean value, only for an actual boolean.

Int(1) is deliberately not a boolean: the type check happens before any coercion, so a file that writes 1 for a flag reads as “absent, use the default”.

Source

pub fn as_int(&self) -> Option<i64>

The integer value of any object that has one, in the C-integer view.

Booleans count as 0 and 1, reals truncate toward zero (saturating, NaN to 0), and everything else has no integer value. Note this is not a type test — use Object::as_number for “is this a number”.

Source

pub fn number(&self) -> Option<f32>

The numeric value of a number, coercing integers to f32.

Only numbers have one — unlike Object::as_int, a boolean does not count.

Source

pub fn as_number(&self) -> Option<&Self>

The number itself, for accessors that type-check before coercing.

Source

pub fn as_string(&self) -> Option<&PdfString>

The string, only for an actual string object.

Source

pub fn as_name(&self) -> Option<&Name>

The name, only for an actual name object.

Source

pub fn as_array(&self) -> Option<&Array>

The array, only for an actual array.

Source

pub fn as_dict(&self) -> Option<&Dict>

The dictionary — of a dictionary object, or of a stream.

Streams answer with their own dictionary, which is what lets page-tree and cross-reference code read /Type off either kind of object without branching.

Source

pub fn as_stream(&self) -> Option<&Stream>

The stream, only for an actual stream.

Source

pub fn as_ref_id(&self) -> Option<ObjRef>

The reference, only for an actual reference.

Source

pub fn is_null(&self) -> bool

Whether this is the null object.

Source

pub fn to_byte_string(&self) -> Vec<u8>

The object’s byte-string spelling.

Booleans spell true/false, numbers spell as the writer would, a string yields its bytes and a name its decoded bytes. Everything else — null, arrays, dictionaries, streams, references — has no spelling and yields empty.

Source

pub fn to_text(&self) -> String

The object read as text: strings and names decode, everything else yields empty.

A stream’s text needs its filters applied first, which this crate cannot do — the reader composes decoding with decode_text instead.

Source

pub fn resolve<'a>(&'a self, r: &impl Resolve) -> Result<Resolved<'a>, Error>

Resolve one level: a reference becomes the object the store holds, anything else is already itself.

The result may still be a reference — an indirect object whose body is 8 0 R resolves to that reference and is not chased further, which is why typed accessors go through Resolved::as_direct.

§Errors

Whatever the store reports for an unresolvable reference.

let direct = Object::Real(1.5);
assert_eq!(direct.resolve(&NoResolve).unwrap().number(), Some(1.5));
// Without a store every reference is dangling.
assert!(Object::Ref(ObjRef::new(4, 0)).resolve(&NoResolve).is_err());
Source

pub fn clone_direct(&self, r: &impl Resolve) -> Self

Deep-copy the object with every reference replaced by what it points at, dropping the edges that would close a cycle. Only a reference back to an ancestor is a cycle; siblings may share substructure and both copies survive. A cut edge disappears — the key or element is omitted rather than becoming null — and an unresolvable reference disappears the same way, indistinguishably.

A reference to a stream flattens into the stream itself, stored directly in the dictionary or array that held it, with its raw, still-encoded bytes and its /Filter intact: ISO 32000-1 §7.3.8.1 constrains a file, not these in-memory types.

let store = Store(HashMap::from([(7, Arc::new(Object::Int(42)))]));
let array = Object::Array(Array::from_iter([Object::Ref(ObjRef::new(7, 0))]));
assert_eq!(
    array.clone_direct(&store),
    Object::Array(Array::from_iter([Object::Int(42)])),
);

Trait Implementations§

Source§

impl<'a> Clone for Resolved<'a>

Source§

fn clone(&self) -> Resolved<'a>

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<'a> Debug for Resolved<'a>

Source§

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

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

impl Deref for Resolved<'_>

Source§

type Target = Object

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Object

Dereferences the value.
Source§

impl PartialEq for Resolved<'_>

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

Auto Trait Implementations§

§

impl<'a> Freeze for Resolved<'a>

§

impl<'a> RefUnwindSafe for Resolved<'a>

§

impl<'a> Send for Resolved<'a>

§

impl<'a> Sync for Resolved<'a>

§

impl<'a> Unpin for Resolved<'a>

§

impl<'a> UnsafeUnpin for Resolved<'a>

§

impl<'a> UnwindSafe for Resolved<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.