Hello,
I would like to implement Deserialize for my struct which represents JSON payload.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Params {
filter: Filter,
}
#[derive(Debug, PartialEq)]
pub struct Filter {
namespace_id: Option<Uuid>,
object_id: Option<String>,
}
And I would like JSON to have a format like
{
"filter": "namespace_id:bab37008-3dc5-492c-af73-80c241241d71 AND object_id:foo"
}
As far as I understand for that I should implement Deserialize
for Filter
.
Unfortunately I don't quite understand how to do it.
I have tried to make it, and it even passes the tests.
You can see the implementation on Playground.
Could you please tell me if I made it right or wrong?
I guess there is a much better way of doing this.
Also, since I have Option
types I can define empty struct and assign the values later on match
.
But what would I do if I wouldn't have Option
?
Also, I am interested in implementation of Serialize
, just for myself, for better understanding.
Maybe you can help with it too?
Thank you.
P. S.
I have implemented Serialize
too but it's very hardcoded.
I guess there is a better way too.