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<'_>
impl Resolved<'_>
Sourcepub fn as_direct(&self) -> Option<&Object>
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.
Sourcepub fn into_owned(self) -> Object
pub fn into_owned(self) -> Object
Take ownership of the object, cloning a borrowed one.
Methods from Deref<Target = Object>§
Sourcepub fn as_bool(&self) -> Option<bool>
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”.
Sourcepub fn as_int(&self) -> Option<i64>
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”.
Sourcepub fn number(&self) -> Option<f32>
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.
Sourcepub fn as_number(&self) -> Option<&Self>
pub fn as_number(&self) -> Option<&Self>
The number itself, for accessors that type-check before coercing.
Sourcepub fn as_dict(&self) -> Option<&Dict>
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.
Sourcepub fn to_byte_string(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn to_text(&self) -> String
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.
Sourcepub fn resolve<'a>(&'a self, r: &impl Resolve) -> Result<Resolved<'a>, Error>
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());Sourcepub fn clone_direct(&self, r: &impl Resolve) -> Self
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)])),
);