-
I can't seem to get the attribute to work. use serde::{Serialize, Deserialize};
use serde_with;
// Makes all struct members public
macro_rules! pub_struct {
($name:ident {$($field:ident: $t:ty,)*}) => {
#[derive(Deserialize, Serialize, Debug, Default)] // ewww
pub struct $name {
$(pub $field: $t),*
}
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct QueryList<T>{
pub query: Vec<T>,
}
pub_struct!(QuerySimple{
endpoint: String,
});
pub_struct!(Criteria {
op: String,
field: String,
value: String,
criteria: Vec<Criteria>,
});
pub_struct!(Reference{
reference: String,
references: Vec<Reference>,
});
#[skip_serializing_none]
#[derive(Serialize, Default)]
pub struct Query {
endpoint: String,
id_int64: Option<i64>,
id_string: String,
criteria: Criteria,
references: Vec<Reference>,
} |
Beta Was this translation helpful? Give feedback.
Answered by
jonasbb
Jun 18, 2019
Replies: 2 comments
-
You cannot use a macro, without importing it first. In your code above, that is missing. -use serde_with;
+use serde_with::skip_serializing_none; or you change -#[skip_serializing_none]
+#[serde_with::skip_serializing_none] then it compiles. Do you have any other problems with the code expect from getting it to compile? |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jonasbb
-
Nope! Thanks for the help. I was expecting that it had the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You cannot use a macro, without importing it first. In your code above, that is missing.
If you change
or you change
then it compiles.
Do you have any other problems with the code expect from getting it to compile?