Skip to content

Single file containing a list of items #811

Discussion options

You must be logged in to vote

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:

#[derive(Serialize, Deserialize)]
struct Parent
{
    item_identifier: Vec<item_identifier>
    // Assuming that the struct item_identifier exists elsewhere
}

And then just read toml::from_str::<Parent>(&file_string)!

Past me was also about to run head-first into item-identifier vs item_identifier (the first not being a valid name), and that can be solved with

#[derive(Serialize, Deserialize)]
#[serde(rename_all="kebab-case")]
struct Parent
{
    items: Vec<item_identifier>
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by probablySophie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants