pub struct Reference { /* private fields */ }Expand description
A reference to another value of the input (r: and R:).
PHP numbers the values of the input in the order they appear (starting
with 1 for the top-level value) and a reference repeats the value of a
number. The deserializer does not resolve references: it passes them
on as extension atoms of this type, the serializer writes them as they
are. Like when deserializing, references have to refer to a value
before them (r: to an object), otherwise they are an error.
This is basically a marker only. The number refers to a position
in the whole input which the value that holds the reference cannot
know, and what it refers to is gone once the input was deserialized:
the values that the types skipped have a number too, and the numbering
rules (keys and R: have no number, r: has one) are those of PHP.
Short of reimplementing the deserializer there is no way to look up the
value. What this type is good for is to detect references and to
write the input back unchanged:
use deser_php::{Reference, ReferenceKind};
// `[$a, &$a]` with `$a = 5`, the second entry refers to the first
let input = b"a:2:{i:0;i:5;i:1;R:2;}";
let value: (u32, Reference) = deser_php::from_slice(input).unwrap();
assert_eq!(value.1, Reference::new(ReferenceKind::Value, 2));
assert_eq!(deser_php::to_vec(&value).unwrap(), input);
// the fallback is the number: this is not the value it refers to
let value: Vec<u32> = deser_php::from_slice(input).unwrap();
assert_eq!(value, [5, 2]);The fallback of the extension is the number, other types than this one receive an integer.