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,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);
}
}
}