1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Indirect-reference lookup: the one seam between the object model and
//! whatever holds the document's objects.
//!
//! **Resolution is one hop.** PDF lets an indirect object's body be itself a
//! reference (`7 0 obj 8 0 R endobj`); a chain like that reads as a *missing
//! value* rather than following to object 8. Every typed accessor in this
//! crate reproduces that — see [`Resolve`] and [`Resolved::as_direct`].
//!
//! Cycle safety is the store's problem, not this crate's: accessors resolve
//! one level by construction and cannot recurse.
use Deref;
use Arc;
use crate::;
/// A store that can produce the object behind a reference.
///
/// **Resolution is one hop: a reference to a reference is absent.** A typed
/// accessor that takes a `&impl Resolve` follows at most one `n g R`; if
/// what it finds there is itself a reference, the value reads as missing
/// rather than being chased further ([`Resolved::as_direct`]).
///
/// Implementations must look up by object *number* alone and ignore the
/// generation: a `12 3 R` in a real file resolves to whatever object 12 the
/// cross-reference table delivers, whatever generation it carries.
/// Unresolvable references — free entries, missing objects, cycles — return
/// [`Error::UnresolvedRef`] or [`Error::RefLoop`], which every typed accessor
/// then reads as absence.
/// 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));
/// ```
/// A resolver that knows nothing, for reading dictionaries whose references
/// are irrelevant (or before a store exists).
///
/// Every reference is unresolvable, which is exactly how a damaged file's
/// dangling references behave, so accessors keep working and return their
/// fallbacks.
///
/// ```
/// use pdfrum_object::{Dict, NoResolve, Object, names};
///
/// let dict = Dict::from_pairs([(names::LENGTH.clone(), Object::Int(7))]);
/// // Direct values still read fine without a store.
/// assert_eq!(dict.int(names::LENGTH, &NoResolve), Some(7));
/// ```
;