Skip to content

serde_as on struct or struct tuple values #518

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

You must be logged in to vote

The serde_as attribute is a replacement for serde's with attribute. As such, it only works on fields and not on structs. https://docs.rs/serde_with/2.0.1/serde_with/guide/serde_as/index.html#switching-from-serdes-with-to-serde_as

Your last example looks almost right. You need an additional attribute before the derive. Try adding #[serde_with::serde_as] at the beginning.

If your Base64 type is also from serde_with there is another problem. The Base64 type only works with types implementing AsRef<[u8]>, but Vec<T> is not one of them. It only works for the special case when your T is u8.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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