fix port binding

This commit is contained in:
Maple 2026-03-24 15:48:56 +01:00
commit 785341e883
43 changed files with 1543 additions and 431 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "macros"
version = "0.0.0"
authors = ["DJMrTV <tvnebel@gmail.com>"]
authors = ["RusticMaple <tvnebel@gmail.com>"]
description = "A `cargo generate` template for quick-starting a procedural macro crate"
keywords = ["template", "proc_macro", "procmacro"]
edition = "2018"
@ -14,4 +14,3 @@ doctest = false
quote = "1.0.38"
proc-macro2 = "1.0.93"
syn = { version = "2.0.98", features = ["full"] }

View file

@ -48,7 +48,11 @@ impl Parse for ProtoInputParams {
fn gen_serialize_data_struct(
s: DataStruct,
struct_attr: Option<&Attribute>,
) -> (proc_macro2::TokenStream, proc_macro2::TokenStream, proc_macro2::TokenStream) {
) -> (
proc_macro2::TokenStream,
proc_macro2::TokenStream,
proc_macro2::TokenStream,
) {
let serialize_base_content = {
let mut serialize_content = quote! {};
@ -123,8 +127,6 @@ fn gen_serialize_data_struct(
let mut size_content = quote! { 0 };
for f in &s.fields {
let ident = f.ident.as_ref().unwrap();
size_content.append_all(quote! {
@ -135,12 +137,11 @@ fn gen_serialize_data_struct(
size_content
};
let write_size = if let Some(_) = struct_attr {
quote!{ #write_size + if rnex_core::config::FEATURE_HAS_STRUCT_HEADER{ 5 } else { 0 } }
quote! { #write_size + if rnex_core::config::FEATURE_HAS_STRUCT_HEADER{ 5 } else { 0 } }
} else {
write_size
};
// generate base with extends stuff
let serialize_base_content = if let Some(attr) = struct_attr {
@ -215,7 +216,7 @@ fn gen_serialize_data_struct(
deserialize_base_content
};
let write_size = quote!{
let write_size = quote! {
fn serialize_write_size(&self) -> rnex_core::rmc::structures::Result<u32>{
Ok(#write_size)
}
@ -390,7 +391,7 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream {
Ok(val)
};
(serialize_base_content, deserialize_base_content, quote!{})
(serialize_base_content, deserialize_base_content, quote! {})
}
Data::Union(_) => {
unimplemented!()

View file

@ -1,47 +1,46 @@
use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote, ToTokens};
use syn::{LitInt, LitStr, ReturnType, Type};
use syn::token::{Brace, Paren, Semi};
use syn::{Attribute, LitInt, LitStr, ReturnType, Type};
pub struct ProtoMethodData{
pub struct ProtoMethodData {
pub id: LitInt,
pub name: Ident,
pub parameters: Vec<(Ident, Type)>,
pub ret_val: ReturnType,
}
/// This is a representation of the code generated by `rmc_proto` it serves to split the logic of
/// acquiring data from the actual generation to tidy up the process into first getting then
/// generating.
///
/// Use the [`ToTokens`] trait to generate the actual code.
pub struct RmcProtocolData{
pub struct RmcProtocolData {
pub has_returns: bool,
pub id: LitInt,
pub name: Ident,
pub methods: Vec<ProtoMethodData>
pub methods: Vec<ProtoMethodData>,
}
impl RmcProtocolData{
fn generate_raw_trait(&self, tokens: &mut TokenStream){
let Self{
impl RmcProtocolData {
fn generate_raw_trait(&self, tokens: &mut TokenStream) {
let Self {
has_returns,
name,
id,
methods
methods,
} = self;
// this gives us the name which the identifier of the corresponding Raw trait
let raw_name = Ident::new(&format!("Raw{}", name), name.span());
// boilerplate tokens which all raw traits need
quote!{
quote! {
#[doc(hidden)]
#[allow(unused_must_use)]
pub trait #raw_name: #name
}.to_tokens(tokens);
}
.to_tokens(tokens);
// generate the body of the raw protocol trait
Brace::default().surround(tokens, |tokens|{
@ -191,9 +190,10 @@ impl RmcProtocolData{
});
});
quote!{
quote! {
impl<T: #name> #raw_name for T{}
}.to_tokens(tokens);
}
.to_tokens(tokens);
}
fn generate_raw_remote_trait(&self, tokens: &mut TokenStream) {
@ -208,13 +208,13 @@ impl RmcProtocolData{
// this gives us the name which the identifier of the corresponding Raw trait
let remote_name = Ident::new(&format!("Remote{}", name), name.span());
// boilerplate tokens which all raw traits need
quote!{
quote! {
#[doc(hidden)]
#[allow(unused_must_use)]
pub trait #remote_name: rnex_core::rmc::protocols::HasRmcConnection
}.to_tokens(tokens);
}
.to_tokens(tokens);
// generate the body of the raw protocol trait
Brace::default().surround(tokens, |tokens|{
@ -299,35 +299,29 @@ impl RmcProtocolData{
})
}
});
}
fn generate_raw_info(&self, tokens: &mut TokenStream){
let Self{
name,
id,
..
} = self;
fn generate_raw_info(&self, tokens: &mut TokenStream) {
let Self { name, id, .. } = self;
let raw_info_name = Ident::new(&format!("Raw{}Info", name), Span::call_site());
quote!{
quote! {
#[doc(hidden)]
pub struct #raw_info_name;
impl #raw_info_name {
pub const PROTOCOL_ID: u16 = #id;
}
}.to_tokens(tokens);
}
.to_tokens(tokens);
}
}
impl ToTokens for RmcProtocolData{
impl ToTokens for RmcProtocolData {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.generate_raw_trait(tokens);
self.generate_raw_info(tokens);
self.generate_raw_remote_trait(tokens);
}
}
}