pub enum Object {
Null,
Boolean(bool),
Integer(i64),
Real(f64),
String(Vec<u8>),
Name(Name),
Array(Vec<Object>),
Dict(Dict),
Stream(Stream),
Reference(ObjId),
}Expand description
A COS object (§7.3.1’s eight basic types, plus the indirect reference, which is a value position in its own right per §7.3.10’s substitutability rule).
Exhaustive on purpose: §7.3.1 closes the set, and matches over it in other crates (the structure dump) rely on a new variant being a compile error rather than a wildcard.
Variants§
Null
null (§7.3.9). Also the resolution of any dangling reference
(§7.3.10 — “shall not be considered an error”).
Boolean(bool)
true / false (§7.3.2).
Integer(i64)
Integer (§7.3.3). Kept distinct from Real — see module docs.
Real(f64)
Real (§7.3.3).
String(Vec<u8>)
String (§7.3.4), decoded to raw bytes (escapes/hex applied). Interpretation as text (§7.9.2) is a later layer’s concern.
Name(Name)
Name (§7.3.5), decoded.
Array(Vec<Object>)
Array (§7.3.6) — heterogeneous, possibly empty.
Dict(Dict)
Dictionary (§7.3.7).
Stream(Stream)
Stream (§7.3.8). Streams only occur as the body of an indirect object (§7.3.8.1 “all streams shall be indirect objects”); the parser enforces that.
Reference(ObjId)
An indirect reference N G R (§7.3.10) — a pointer, resolved
on demand by the document layer (dangling → Null, generation
mismatch → Null, cycle-guarded).
Implementations§
Source§impl Object
impl Object
Sourcepub const fn as_number(&self) -> Option<f64>
pub const fn as_number(&self) -> Option<f64>
This object as a number, widening integer to f64 — the §7.3.3 NOTE 2 rule (“wherever a real number is expected, an integer may be used instead”). The converse direction is deliberately NOT offered.
Sourcepub fn as_dict(&self) -> Option<&Dict>
pub fn as_dict(&self) -> Option<&Dict>
This object as a dictionary, if it is one — a plain dict OR a stream’s dict (a stream is usable anywhere its dictionary content is what matters).
Sourcepub const fn as_reference(&self) -> Option<ObjId>
pub const fn as_reference(&self) -> Option<ObjId>
This object as an indirect reference, if it is one.
Trait Implementations§
Source§impl Display for Object
impl Display for Object
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
One unstyled line, sentence-sized: scalars exact, containers named
rather than expanded (Pass 296.2).
| variant | renders as |
|---|---|
Null | null |
Boolean | true / false |
Integer | 12 |
Real | 1.5 |
String | (Hello), or <0102FF> when it is not printable text |
Name | /PageMode |
Array | an array of 3 items |
Dict | a dictionary of 14 entries |
Stream | a stream of 14 entries |
Reference | 12 0 R |
§Why containers are NAMED and not expanded
The request this answers put it better than a restatement would: the
pair being shown is kept versus discarded and the operator’s
question is “did pdfcer pick the right one?”. A graph dumped into a
status-bar sentence makes the readable case unreadable too — one
enormous value destroys the line that the small value beside it was
going to fit on.
So this is not a serialiser and must not become one. Debug remains
the full graph and has not changed; crate::writer remains the way
to produce bytes. This is the operator’s sentence, and a caller that
wants a container’s contents should ask for them.
§Why the engine owns this at all
Three things were diverging across consumers, none of which fails a
test: the slash on a name, whether a container expands, and — the one
that bites silently — the #[non_exhaustive] wildcard. A shell’s
catch-all arm renders “a value this build does not recognise”, so
adding a variant here would quietly make every shell say that about
it. Owning Display means the arm is added in the same commit as the
variant, by the person who knows what it is.
The precedent was already set by ObjId, which is Display and
renders 12 0 — the form found in the bytes. The absence of the same
on Object read as an oversight because it was one.
§Not in scope
Localisation, wrapping, truncation, width awareness. Those belong to whoever is drawing the line.