Skip to content

Using serde_with to deserialize from string or struct on a vector #333

Answered by jonasbb
colmanhumphrey asked this question in Q&A
Discussion options

You must be logged in to vote

That is my mistake, I was too brief in the other message. To use serde_as you need to place the proc-macro attribute #[serde_with::serde_as] before the derive. This section of the user guide explains how to setup everything and what you can do with it.

#[serde_with::serde_as]
#[derive(Deserialize, Debug)]
pub struct ManyBuilds {
    some_fields_with_overall_info: i32, // etc
    #[serde_as(as = "Vec<PickFirst<(_, DisplayFromStr)>>")]
    builds: Vec<Build>
}

Side-Note: The associated Err type on the FromStr implementations needs to implement Display for this to work.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@colmanhumphrey
Comment options

Answer selected by jonasbb
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