Single file containing a list of items #811
-
Hi, I was hoping to read a file A super simple abstraction of the TOML file I'm hoping to read
The line of code I currently have for parsing let Ok(extracted) = toml::from_str::<T>(&file_string) Everything's fine when reading from a file containing a single item's key/value pairs and no [[item-identifier]]
Its just when I want to add identifiers that everything falls apart. Error message
I know I can just (And the reason I want to do this specifically is that I'm following some specification docs and I'd really rather not create a different file layout) Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
I have solutions that do exactly what past me wanted! Reading multiple items from a file: Instead of trying to read a #[derive(Serialize, Deserialize)]
struct Parent
{
item_identifier: Vec<item_identifier>
// Assuming that the struct item_identifier exists elsewhere
} And then just read Past me was also about to run head-first into #[derive(Serialize, Deserialize)]
#[serde(rename_all="kebab-case")]
struct Parent
{
items: Vec<item_identifier>
} |
Beta Was this translation helpful? Give feedback.
I have solutions that do exactly what past me wanted!
Reading multiple items from a file:
Instead of trying to read a
Vec<item-identifier>
, create a parent Struct:And then just read
toml::from_str::<Parent>(&file_string)
!Past me was also about to run head-first into
item-identifier
vsitem_identifier
(the first not being a valid name), and that can be solved with