Skip to content

Trying to understand newtype behavior #768

Answered by mitsuhiko
dfego asked this question in Q&A
Discussion options

You must be logged in to vote

When you say my first option is to use serde, am I not already doing that? I'm pretty sure I had to derive Serialize to get it to compile in my example. If not via serde, how is my struct currently getting serialized?

You are doing that, but you then get the behavior that serde implements for newtypes. Which for newtypes is just serializing what's inside. You either need to implement a custom serializer on Public or you need to use Object. To detect if you are serializing for minijinja uses within a serde serializer you can use this method to customize it: https://docs.rs/minijinja/latest/minijinja/value/fn.serializing_for_value.html

But now that I'm thinking about it further, are you …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@dfego
Comment options

@mitsuhiko
Comment options

Answer selected by dfego
@dfego
Comment options

@mitsuhiko
Comment options

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