From 9e305eaebeeaba64649d3c39b22003ba9be1a407 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sun, 23 Feb 2025 13:18:30 +0100 Subject: fix ircchannel and maplist network representation --- derive/src/network/maplist.rs | 32 +++++++++++--------------------- derive/src/network/mod.rs | 35 +++++++++++++++++------------------ 2 files changed, 28 insertions(+), 39 deletions(-) (limited to 'derive') diff --git a/derive/src/network/maplist.rs b/derive/src/network/maplist.rs index ebda601..8ce18c5 100644 --- a/derive/src/network/maplist.rs +++ b/derive/src/network/maplist.rs @@ -1,7 +1,7 @@ use proc_macro2::{Ident, TokenStream}; use quote::quote; -use crate::network::{get_field_variant_type, gen_type}; +use crate::network::{gen_type, get_field_type}; use super::NetworkField; @@ -16,7 +16,6 @@ pub(crate) fn to(fields: &Vec) -> Vec { }; let field_name = field.ident.as_ref().unwrap(); - let field_type = get_field_variant_type(&field); let field_inner = match field.network { crate::network::NetworkRepr::List => quote! { @@ -30,10 +29,10 @@ pub(crate) fn to(fields: &Vec) -> Vec { }, }; - if let Some(_) = field.variant { + if field.stringlist { quote! { res.insert(#field_rename.to_string(), - libquassel::primitive::Variant::#field_type( + libquassel::primitive::Variant::StringList( std::vec::from_elem(#field_inner, 1))); } } else { @@ -69,7 +68,7 @@ pub(crate) fn to_vec(_type_name: &Ident, fields: &Vec) -> TokenStr let field_type = match field.network { crate::network::NetworkRepr::List => gen_type("VariantList"), crate::network::NetworkRepr::Map => gen_type("VariantMap"), - crate::network::NetworkRepr::None => get_field_variant_type(&field), + crate::network::NetworkRepr::None => get_field_type(&field), }; let field_inner = match field.network { @@ -86,7 +85,7 @@ pub(crate) fn to_vec(_type_name: &Ident, fields: &Vec) -> TokenStr // FIXME this section doesn't make any sense to me anymore // why do we select a StringList if we have configured a variant??? - if let Some(_) = field.variant { + if field.stringlist { lists.push(quote! { let mut #field_name: libquassel::primitive::StringList = Vec::with_capacity(self.len()); }); @@ -148,8 +147,6 @@ pub(crate) fn from(fields: &Vec) -> Vec { None => format!("{}", field.ident.as_ref().unwrap()).into(), }; - let field_type = get_field_variant_type(&field); - let field_inner = match field.network { super::NetworkRepr::List => quote! { libquassel::message::NetworkList::from_network_list(&mut std::convert::TryInto::try_into(input.remove(0)).unwrap()) @@ -162,10 +159,10 @@ pub(crate) fn from(fields: &Vec) -> Vec { }, }; - if let Some(_) = field.variant { + if field.stringlist { quote! { #field_name: match input.get_mut(#field_rename).unwrap() { - libquassel::primitive::Variant::#field_type(input) => #field_inner, + libquassel::primitive::Variant::StringList(input) => #field_inner, _ => panic!("#field_name: wrong variant") }, } @@ -190,17 +187,10 @@ pub(crate) fn from_vec(type_name: &Ident, fields: &Vec) -> TokenSt None => format!("{}", field.ident.as_ref().unwrap()).into(), }; - let _field_name = field.ident.as_ref().unwrap(); - - let _field_type = get_field_variant_type(field); - - let field_variant = match &field.variant { - None => quote! {libquassel::primitive::VariantList}, - Some(variant_type) => match variant_type.as_str() { - "StringList" => quote! {libquassel::primitive::StringList}, - "VariantMap" => quote! {libquassel::primitive::VariantMap}, - _ => quote! {libquassel::primitive::VariantMap}, - }, + let field_variant = if field.stringlist { + quote! {libquassel::primitive::StringList} + } else { + quote! {libquassel::primitive::VariantList} }; let inner = quote! { diff --git a/derive/src/network/mod.rs b/derive/src/network/mod.rs index aea8080..da8e718 100644 --- a/derive/src/network/mod.rs +++ b/derive/src/network/mod.rs @@ -61,6 +61,12 @@ pub struct NetworkField { /// Skips this field when serializing to network representation #[darling(default)] skip: bool, + + /// Special reprensentation case for NetworkMap maplist repr + /// in which case if the field is a String a StringList will be used instead of a VariantList + /// this cannot be switched with variant as that leads to collisions with the other network representations + #[darling(default)] + stringlist: bool, } fn parse_fields(input: &syn::DeriveInput) -> Vec { @@ -85,14 +91,11 @@ pub fn network_map(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let mut fields = parse_fields(&input); let quassel_fields = super::QuasselField::parse(&input); - fields - .iter_mut() - .zip(quassel_fields) - .for_each(|(field, qfield)| { - if field.rename.is_none() { - field.rename = qfield.name - } - }); + fields.iter_mut().zip(quassel_fields).for_each(|(field, qfield)| { + if field.rename.is_none() { + field.rename = qfield.name + } + }); let name = &input.ident; @@ -171,14 +174,11 @@ pub fn network_list(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let mut fields = parse_fields(&input); let quassel_fields = super::QuasselField::parse(&input); - fields - .iter_mut() - .zip(quassel_fields) - .for_each(|(field, qfield)| { - if field.rename.is_none() { - field.rename = qfield.name - } - }); + fields.iter_mut().zip(quassel_fields).for_each(|(field, qfield)| { + if field.rename.is_none() { + field.rename = qfield.name + } + }); let name = &input.ident; @@ -227,8 +227,7 @@ fn gen_type(typ: &str) -> syn::Type { path: syn::Path { leading_colon: None, segments: { - let mut res = - syn::punctuated::Punctuated::::new(); + let mut res = syn::punctuated::Punctuated::::new(); res.push(syn::PathSegment { ident: syn::Ident::new(typ, proc_macro2::Span::call_site()), -- cgit v1.2.3 01' title='2026-02-21 14:35:01 +0100'>10 daysclean up clippy lintsMax Audron-259/+242 10 daysreplace all match_variant instances with try_intoMax Audron-134/+111 the match_variant macro was unclear, unreadable and no longer needed as we have automaticly derived from implementations for all Variant enum fields now 2025-07-27remove old readme.orgMax Audron-35/+0 2025-07-27temporarly fix nested network repr parsing for variant typesMax Audron-39/+39 2025-07-27fix sessioninit message wrongly using NetworkMap to convert a fieldMax Audron-4/+5 2025-03-03update roadmapMax Audron-2/+10 2025-03-01implement rpc callsMax Audron-64/+762 2025-03-01add UserType implementation for required signalproxy objectsMax Audron-13/+131 2025-03-01remove old quassel attributes from derive macrosMax Audron-37/+36 this was used across the different derive macros and already replace by macro specific network and setter attributes. 2025-02-27extend docs and reorganize filesMax Audron-1281/+321 2025-02-26implement NetworkId UserTypeMax Audron-108/+196 2025-02-26implement IdentityIdMax Audron-8/+79 2025-02-26refactor variant deserializationMax Audron-123/+59 2025-02-26refactor deserialize and serializevariant traitMax Audron-90/+80 move stuff around a bit to sepperate it out for deserializevariant 2025-02-26refactor variant serialization codeMax Audron-256/+405 Factored out a lot of the serialization of variants into trait's that have auto impl so code duplication is much reduced 2025-02-26add MsgId and BufferId to objects where neededMax Audron-141/+157 some objects where still handling BufferId or MsgId as their raw types which lead to errors now that the Types are properly parsed in the varinats 2025-02-25enable transparent repr for msgid and bufferidMax Audron-0/+2 2025-02-25Implement BacklogManagerTobias Deiminger-59/+113 2025-02-25Use BufferId in BufferInfoTobias Deiminger-10/+11 2025-02-25Use BufferId in VariantTobias Deiminger-2/+33 2025-02-25Add BufferId as Rust typeTobias Deiminger-0/+39 Up to now it was represented as i32. If we introduce a newtype for it, we can handle it idiomatically as dedicated Variant::BufferId variant (instead of having it mashed into Variant::UserType). 2025-02-25Use MsgId in MessageTobias Deiminger-18/+6 2025-02-25Use MsgId in VariantTobias Deiminger-20/+37 2025-02-25Add MsgId as Rust typeTobias Deiminger-0/+56 Up to now it was handled implicitely in Variant::UserType. Making it an explicit type allows to centralize the i32/i64 cfg dependency and to use the type for arguments in signalproxy::objects functions. 2025-02-24added session manager comments and log messageMax Audron-1/+3 2025-02-23add identity syncable to SessionManagerMax Audron-1/+8 2025-02-23add syncables for IrcUserMax Audron-2/+53 2025-02-23move network config to it's own file and impl it's syncMax Audron-23/+84 2025-02-23add basic network syncablesMax Audron-39/+420 2025-02-23clean up unused_import and unused_variables a bitMax Audron-2/+8 2025-02-23fix server feature errorsMax Audron-28/+23 2025-02-23fix ircchannel and maplist network representationMax Audron-154/+137 2025-02-22replace deprecated failure crate with thiserrorMax Audron-278/+194 this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense. 2025-02-22update dependencies and fix errorsMax Audron-508/+332 2025-02-22update flakeMax Audron-94/+117 2024-05-22add todos to readmeMax Audron-16/+35