Skip to main content

unparse

Function unparse 

Source
pub fn unparse<V: AsRef<Value>>(
    source: &Source,
    value: V,
) -> Result<String, Box<dyn Error + Send + Sync + 'static>>
Expand description

Serialize a Value map into dotenv / env-file KEY=VALUE lines.

Accepts a Value, &Value, LocatedValue, or &LocatedValue; the root must be a Value::Map. Nested maps are flattened using the separator option carried by source (the same option Env::parse reads); a nested map with no separator configured is an error, as are lists (env has no list representation).

use tanzim_parse::env::unparse;
use tanzim_source::SourceBuilder;
use tanzim_value::{Map, LocatedValue, Location, Value};

let source = SourceBuilder::new().with_source("env").build().unwrap();
let mut map = Map::new();
map.insert("port".into(), LocatedValue::new(
    Value::String("8080".into()),
    Location::at("env", "", None, None, None),
));
assert_eq!(unparse(&source, Value::Map(map)).unwrap(), "port=8080\n");