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
//! A dynamic value type for deser.
//!
//! [`Value`] can hold any value of the deser data model. It's useful for
//! data whose structure is not known up front, to inspect or transform data
//! before it's deserialized into a type, or to convert between formats:
//!
//! ```
//! use deser_value::{Value, value};
//!
//! let mut config: Value =
//! deser_json::from_str(r#"{"name": "app", "port": 8080}"#).unwrap();
//! config["port"] = value!(9090);
//! config["tags"] = value!(["web", "prod"]);
//! assert_eq!(
//! deser_json::to_string(&config).unwrap(),
//! r#"{"name":"app","port":9090,"tags":["web","prod"]}"#
//! );
//! ```
//!
//! Values are converted from and into other types with [`to_value`] and
//! [`from_value`]. To configure the conversion (for instance to add
//! layers) use the [`Serializer`] and the [`Deserializer`]. Values can be
//! built with the [`value!`] macro.
//!
//! # Retained Information
//!
//! Values try to retain as much information as possible, which means that
//! a value that is deserialized and serialized again comes out the same:
//!
//! * Map keys can be any value (like integers in CBOR) and maps retain the
//! order of their entries.
//! * Values that extend the data model (like date-times, UUIDs or exact
//! numbers, see [`deser::ext`](deser_core::ext)) retain their type.
//! * Maps and sequences retain their [`Order`](deser_core::Order).
//! * Bytes retain their [fallback](deser_core::Bytes::fallback).
//! * [Event data](deser_core::State::event), which is information that is
//! attached to values but not part of the data model (for instance CBOR
//! tags or formatting hints), is retained in the [`Meta`] data of values.
//! * If the format tracks locations (see
//! [`TrackLocations`](deser_core::TrackLocations)), values retain their
//! [`Span`] in the input. Types that are deserialized from such values
//! report errors at the original location:
//!
//! ```
//! use deser::{Context, Deserialize, TrackLocations};
//! use deser_value::{Value, from_value};
//!
//! #[derive(Debug, Deserialize)]
//! struct Config {
//! port: u16,
//! }
//!
//! let config = deser_json::DeserializerConfig::builder()
//! .context(Context::with(TrackLocations(true)))
//! .build();
//! let value: Value = config.from_str("{\n \"port\": \"80\"\n}").unwrap();
//! let err = from_value::<Config>(&value).unwrap_err();
//! assert_eq!((err.line(), err.column()), (Some(2), Some(11)));
//! ```
//!
//! # Duplicate Keys
//!
//! Map keys are unique. If a key is given more than once, the
//! [`DuplicateKeys`](deser_core::de::DuplicateKeys) policy of the
//! deserialization decides: by default the deserialization fails, otherwise
//! the first or the last value is used. The keys of multimaps (like the
//! parameters of query strings) collect their values instead, see
//! [`Seq::is_repeated`].
pub use ;
pub use ValueIndex;
pub use ;
pub use Seq;
pub use ;
// values must never prevent data from being shared between threads.
const _: = ;