Custom deserialize of u16 into a Vec<u16>

#1

I have a custom deserialize function to deserialize a u16 from either a number, like 10, or String as a hex value, like “0x10”, its pretty straightforward. Its works great for single values, however i want to expand it so i can deserialize an array [10, “0x10”] into a Vec. I feel like there should be an elegant solution to this, but i can’t seem to find it. Any help would be appreciated.

I have a complete example in the playground.

Playground Sample Code

Thanks!

0 Likes

#2

TOML does not permit mixed types in an array. See the spec: “Data types may not be mixed”. So this won’t be possible in TOML unless you write your own non-conforming TOML library or select a different format.

0 Likes

#3

Ahhh, (facepalm) … that makes perfect sense. I was trying to be too fancy i’ll stick with the standard toml formatting. I really appreciate the response.

0 Likes