| 207 | |
| 208 | pub fn toml2dict<'a>(py: Python<'a>, args: &toml::value::Table) -> PyResult<&'a PyDict> { |
| 209 | fn append_list(py: Python, value: &toml::Value, list: &PyList) -> PyResult<()> { |
| 210 | match value { |
| 211 | toml::Value::String(s) => list.append(s), |
| 212 | toml::Value::Float(f) => list.append(f), |
| 213 | toml::Value::Integer(i) => list.append(i), |
| 214 | toml::Value::Boolean(b) => list.append(b), |
| 215 | toml::Value::Datetime(t) => list.append(t.to_string()), |
| 216 | toml::Value::Array(l) => { |
| 217 | let pylist = PyList::empty(py); |
| 218 | for e in l { |
| 219 | append_list(py, e, pylist)?; |
| 220 | } |
| 221 | list.append(pylist) |
| 222 | } |
| 223 | toml::Value::Table(d) => { |
| 224 | let pydict = PyDict::new(py); |
| 225 | for (key, value) in d { |
| 226 | fill_dict(py, key, value, pydict)?; |
| 227 | } |
| 228 | list.append(pydict) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | fn fill_dict(py: Python, key: &str, value: &toml::Value, dict: &PyDict) -> PyResult<()> { |
| 233 | match value { |
| 234 | toml::Value::String(s) => dict.set_item(key, s), |