aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-02-10 15:29:36 -0800
committerAlex Crichton <alex@alexcrichton.com>2017-02-10 15:29:36 -0800
commit79fc6c3fcbc2e77d25e18d5ef5bcd160ff9c900a (patch)
tree068c0cb7d5bf10b05154e0447b280d5b91ee2b47 /tests
parentf4f0c2ca7bdc0d04d3c4947d30a2cbfbfd024e16 (diff)
downloadmilf-rs-79fc6c3fcbc2e77d25e18d5ef5bcd160ff9c900a.tar.gz
milf-rs-79fc6c3fcbc2e77d25e18d5ef5bcd160ff9c900a.zip
Add a serialization helper to put tables last
This should help serializing maps where it's unknown up front whether the tables and/or values come first. Closes #142
Diffstat (limited to 'tests')
-rw-r--r--tests/tables-last.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/tables-last.rs b/tests/tables-last.rs
new file mode 100644
index 0000000..d05c8f0
--- /dev/null
+++ b/tests/tables-last.rs
@@ -0,0 +1,30 @@
+#[macro_use]
+extern crate serde_derive;
+extern crate toml;
+
+use std::collections::HashMap;
+
+#[derive(Serialize)]
+struct A {
+ #[serde(serialize_with = "toml::ser::tables_last")]
+ vals: HashMap<&'static str, Value>,
+}
+
+#[derive(Serialize)]
+#[serde(untagged)]
+enum Value {
+ Map(HashMap<&'static str, &'static str>),
+ Int(i32),
+}
+
+#[test]
+fn always_works() {
+ let mut a = A { vals: HashMap::new() };
+ a.vals.insert("foo", Value::Int(0));
+
+ let mut sub = HashMap::new();
+ sub.insert("foo", "bar");
+ a.vals.insert("bar", Value::Map(sub));
+
+ toml::to_string(&a).unwrap();
+}