Skip to main content

to_value

Function to_value 

Source
pub fn to_value<T>(value: &T) -> Result<Value>
where T: ?Sized + Serialize,
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::SerializeT’s Serialize impl returned an error.
  • Error::Custom — surfaces upstream serde_core::ser::Error conversions that don’t fit the structured variants.