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
//! Reads a typed value from the located tree a [format](crate::format::Format)
//! read.
//!
//! One serde Deserializer serves every format: it walks the [tree](crate::tree)
//! and asks the format to resolve each scalar for the type the field needs, so
//! each format keeps its own scalar rules. A problem comes back as a
//! [`Refusal`] with a [`Fault`](crate::format::Fault)
//! and the bytes it sits at; [`Messages`](crate::Messages) words the fault.
//!
//! [`Tagged`] reads a node's tag beside its value.
//!
//! [`Input`](crate::Input) reads every typed value through this module.
use PhantomData;
use ;
use DeserializeOwned;
pub use Tagged;
use crate;
use crateNode;
/// Reads a `T` from `node`, a tree `format` read, resolving each scalar by
/// `format`'s rules.
///
/// The mapping and sequence rules are the same for every format. A struct or
/// a map needs a mapping, and a sequence, a tuple or a tuple struct needs a
/// sequence. An enum is a scalar naming a unit variant, or a mapping of one
/// entry from the variant to its content. An `Option` is `None` for a scalar
/// that resolves as null and `Some` for any other node.
///
/// # Errors
///
/// A [`Refusal`] naming the fault and the bytes it sits at: the node the
/// fault arose in, or the alias that replayed it with
/// [`Refusal::defined_at`] naming where its value is written. A missing field
/// sits on the key whose value is the mapping that lacks it, or at the start
/// of the text for the root mapping.
///
/// ```
/// # #[cfg(feature = "yaml")]
/// # {
/// use ctl_input::Limits;
/// use ctl_input::de::deserialize;
/// use ctl_input::format::{Format, Reading, YAML};
/// use serde::Deserialize;
///
/// #[derive(Debug, Deserialize, PartialEq)]
/// struct Config {
/// port: u16,
/// }
///
/// let tree = YAML.read("port: '8080'\n", &Limits::NONE, Reading::Strict)?;
/// let config: Config = deserialize(&tree, &YAML)?;
/// assert_eq!(config, Config { port: 8080 });
/// # }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```