pub fn to_value<T>(value: &T) -> Result<Value>Expand description
Serialize a Rust value into a dynamic Value tree via the
Serde data model.
Use this when the typed serialise output should land in
noyalib’s Value for further programmatic editing
(Value::merge, Value::interpolate_properties, …) before a
final emit.
Note: TaggedValue’s Serialize impl (which Value::Tagged
delegates to) routes through serialize_map with a single entry keyed
by the tag string — the right shape for interop with a generic
serializer that has no YAML-tag concept, serde_json and friends
included — wrapped in a newtype struct carrying a private marker name.
This crate’s own Serializer does have a tag concept: it
recognises the marker (never the map’s shape) when it builds the
resulting Value and reconstructs Value::Tagged, so
to_value/to_string on a Value containing Tagged round-trips the
tag rather than losing it to a degenerate one-entry mapping, while a
genuine one-entry mapping keyed by a !-string stays a mapping. Refs
#350, #377. For direct emission of a Value you already hold, without going
through the Serialize pipeline at all, see to_string_value /
to_writer_value.
§Errors
Error::Serialize—T’sSerializeimpl returned an error.Error::Custom— surfaces upstreamserde_core::ser::Errorconversions that don’t fit the structured variants.