From 2c6a695ace79ff2a7218c69b387c083a8c1497c6 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 2 May 2024 08:54:18 +0200 Subject: [PATCH] remove unused macros --- examples/nrf-sdc/Cargo.toml | 1 - host-macros/Cargo.toml | 24 ---------- host-macros/src/lib.rs | 87 ------------------------------------- host/Cargo.toml | 1 - 4 files changed, 113 deletions(-) delete mode 100644 host-macros/Cargo.toml delete mode 100644 host-macros/src/lib.rs diff --git a/examples/nrf-sdc/Cargo.toml b/examples/nrf-sdc/Cargo.toml index 3485f42..2b655c1 100644 --- a/examples/nrf-sdc/Cargo.toml +++ b/examples/nrf-sdc/Cargo.toml @@ -16,7 +16,6 @@ nrf-sdc = { version = "0.1.0", default-features = false, features = ["defmt", "n nrf-mpsl = { version = "0.1.0", default-features = false, features = ["defmt", "critical-section-impl"] } bt-hci = { version = "0.1.0", default-features = false, features = ["defmt"] } trouble-host = { version = "0.1.0", path = "../../host", features = ["defmt", "gatt"] } -#trouble-host-macros = { version = "0.1.0", path = "../../host-macros" } defmt = "0.3" defmt-rtt = "0.4.0" diff --git a/host-macros/Cargo.toml b/host-macros/Cargo.toml deleted file mode 100644 index 16fd418..0000000 --- a/host-macros/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "trouble-host-macros" -version = "0.1.0" -edition = "2021" -description = "Macros for trouble-host types" -license = "Apache-2.0 or MIT" -keywords = [ - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] -resolver = "2" - -[dependencies] -syn = { version = "2.0.15", features = ["full", "extra-traits"] } -quote = "1.0.9" -darling = "0.20.1" -proc-macro2 = "1.0.81" - -[lib] -proc-macro = true diff --git a/host-macros/src/lib.rs b/host-macros/src/lib.rs deleted file mode 100644 index 5c3601e..0000000 --- a/host-macros/src/lib.rs +++ /dev/null @@ -1,87 +0,0 @@ -extern crate proc_macro; -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_quote, Data, DeriveInput, Fields}; - -#[proc_macro_derive(Codec)] -pub fn derive_codec_fn(item: TokenStream) -> TokenStream { - let ast = syn::parse_macro_input!(item as DeriveInput); - let name = &ast.ident; - - match &ast.data { - Data::Struct(data_struct) => match &data_struct.fields { - Fields::Named(fields) => { - let mut offsets = Vec::new(); - let mut field_constants: Vec<_> = Vec::new(); - let mut field_encoders: Vec<_> = Vec::new(); - let mut field_decoders: Vec<_> = Vec::new(); - - for f in fields.named.iter() { - let fname = &f.ident; - let ftype = &f.ty; - let fsize = quote! { <#ftype as FixedSize>::SIZE }; - - let offset: syn::Expr = if offsets.is_empty() { - parse_quote! { - 0 - } - } else { - parse_quote! { - #(#offsets)+* - } - }; - offsets.push(fsize.clone()); - - field_encoders.push(quote! { - if #offset + #fsize <= dest.len() { - self.#fname.encode(&mut dest[#offset..#offset + #fsize])?; - } else { - return Err(Error::InsufficientSpace); - } - }); - - field_decoders.push(quote! { - #fname : if #offset + #fsize <= src.len() { - <#ftype as Decode>::decode(&src[#offset..#offset + #fsize])? - } else { - return Err(Error::InsufficientSpace); - }, - }); - - field_constants.push(quote! { - <#ftype as FixedSize>::SIZE - }); - } - - quote! { - - impl FixedSize for #name { - const SIZE: usize = #(#field_constants)+*; - } - - impl Encode for #name { - fn encode(&self, dest: &mut [u8]) -> Result<(), Error> { - #(#field_encoders)*; - Ok(()) - } - } - - impl Decode for #name { - fn decode(src: &[u8]) -> Result { - Ok(Self { - #(#field_decoders)* - }) - } - } - } - } - _ => { - panic!("only standard structs please"); - } - } - .into(), - _ => { - panic!("Codec macro can only be used with structs"); - } - } -} diff --git a/host/Cargo.toml b/host/Cargo.toml index d1949a2..49af237 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -22,7 +22,6 @@ embassy-time = "0.3" embassy-futures = "0.1" futures = { version = "0.3", default-features = false } heapless = "0.8" -trouble-host-macros = { version = "0.1.0", path = "../host-macros" } # Logging log = { version = "0.4.16", optional = true }