Derive serde methods on message enums

This commit is contained in:
Kodi Craft 2024-06-20 11:52:36 +02:00
parent 62cffa56ff
commit cc4d14fe69
Signed by: kodi
GPG Key ID: 69D9EED60B242822
3 changed files with 26 additions and 1 deletions

21
Cargo.lock generated
View File

@ -50,6 +50,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde",
"syn", "syn",
"tokio", "tokio",
] ]
@ -120,6 +121,26 @@ version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "serde"
version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.66" version = "2.0.66"

View File

@ -3,10 +3,12 @@ name = "eagle"
version = "0.2.0" version = "0.2.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0" license = "AGPL-3.0"
publish = ["gitea"]
[dependencies] [dependencies]
proc-macro2 = "1.0.85" proc-macro2 = "1.0.85"
quote = "1.0.36" quote = "1.0.36"
serde = { version = "1.0.203", features = ["serde_derive"] }
syn = "2.0.66" syn = "2.0.66"
tokio = { version = "1.38.0", features = ["sync"] } tokio = { version = "1.38.0", features = ["sync"] }
@ -15,4 +17,4 @@ proc-macro = true
[[test]] [[test]]
name = "tests" name = "tests"
path = "tests/mod.rs" path = "tests/mod.rs"

View File

@ -92,6 +92,7 @@ pub fn derive_protocol(input: TokenStream) -> TokenStream {
}; };
let client_enum_name = format_ident!("{}Question", name); let client_enum_name = format_ident!("{}Question", name);
let client_enum = quote! { let client_enum = quote! {
#[derive(serde::Serialize, serde::Deserialize)]
#vis enum #client_enum_name { #vis enum #client_enum_name {
#(#client_enum), * #(#client_enum), *
} }
@ -99,6 +100,7 @@ pub fn derive_protocol(input: TokenStream) -> TokenStream {
// Create an enum to represent the queries the client has sent // Create an enum to represent the queries the client has sent
let query_enum_name = format_ident!("{}Query", name); let query_enum_name = format_ident!("{}Query", name);
let query_enum = quote! { let query_enum = quote! {
#[derive(serde::Serialize, serde::Deserialize)]
#vis enum #query_enum_name { #vis enum #query_enum_name {
#(#query_enum), * #(#query_enum), *
} }