Expand description
Returns a formatted value.
Since formatting is part of a Value
, the right hand side of the
assignment needs to be decorated with a space before the value.
The value
function does just that.
Examples
let mut table = Table::default();
let mut array = Array::default();
array.push("hello");
array.push("\\, world"); // \ is only allowed in a literal string
table["key1"] = value("value1");
table["key2"] = value(42);
table["key3"] = value(array);
assert_eq(table.to_string(),
r#"key1 = "value1"
key2 = 42
key3 = ["hello", '\, world']
"#);
Examples found in repository?
src/index.rs (line 59)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn index_mut<'v>(&self, v: &'v mut Item) -> Option<&'v mut Item> {
if let Item::None = *v {
let mut t = InlineTable::default();
t.items.insert(
InternalString::from(self),
TableKeyValue::new(Key::new(self), Item::None),
);
*v = value(Value::InlineTable(t));
}
match *v {
Item::Table(ref mut t) => Some(t.entry(self).or_insert(Item::None)),
Item::Value(ref mut v) => v.as_inline_table_mut().map(|t| {
&mut t
.items
.entry(InternalString::from(self))
.or_insert_with(|| TableKeyValue::new(Key::new(self), Item::None))
.value
}),
_ => None,
}
}