Skip to main content

to_string

Function to_string 

Source
pub fn to_string(value: &dyn ToToml) -> Result<String, ToTomlError>
Available on crate feature to-toml only.
Expand description

Serializes a ToToml value into a TOML document string with default formatting.

The value must serialize to a table at the top level. For format preservation or custom indentation, use Formatting.

§Errors

Returns ToTomlError if serialization fails or the top-level value is not a table.

§Examples

use std::collections::BTreeMap;
use toml_spanner::to_string;

let mut map = BTreeMap::new();
map.insert("key", "value");
let output = to_string(&map).unwrap();
assert!(output.contains("key = \"value\""));