I'm new to Rust and trying to build something simple to get going. I want to load data from a .toml
file and use rustache to render out some text from it.
Rustache appears to take a HashMap as its data source, and I'm sure from looking at the toml-rs docs that I should be able to convert its Table
and Array
types to HashMap
s and Vec
s, and I suspect it's got something to do with Decoder
, but I can't figure it out.
If somebody could provide a short example of how to do this I would be very grateful.
If your data structure has fixed known depth, then all you need is just to pass a correct type to
toml::decode()
:The code above would parse a document like
However, as far as I can see, rustache provides some kind of builder structure which supports arbitrary nesting. In that case you would need to "apply"
toml::Value
torustache::HashBuilder
. You don't need to useDecodable
for this (though you probably can, with some newtypes) - you just need to write a couple of simple functions:There are unfortunate clones when handling nested tables and arrays - this is a consequence of an issue in rustache. If it is fixed,
clone()
could be removed, and the closures should be mademove
then.