aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/jsonrpc_macro
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-30 20:03:02 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-30 20:03:02 +0200
commit3c55168b72c022b618822c7993b7692f583506db (patch)
tree146c03f6cc19956ec0acfb7ba26a6202cb5a9647 /jsonrpc/jsonrpc_macro
parent2ec4d4a3c3779dc016c8437891f825a54a805808 (diff)
jsonrpc: remove redundant macro codes in the main crate and clean up
internal proc macros
Diffstat (limited to 'jsonrpc/jsonrpc_macro')
-rw-r--r--jsonrpc/jsonrpc_macro/Cargo.toml26
-rw-r--r--jsonrpc/jsonrpc_macro/src/lib.rs85
2 files changed, 0 insertions, 111 deletions
diff --git a/jsonrpc/jsonrpc_macro/Cargo.toml b/jsonrpc/jsonrpc_macro/Cargo.toml
deleted file mode 100644
index cf001e1..0000000
--- a/jsonrpc/jsonrpc_macro/Cargo.toml
+++ /dev/null
@@ -1,26 +0,0 @@
-[package]
-name = "karyon_jsonrpc_macro"
-description = "Internal crate for Karyon library."
-version.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-license.workspace = true
-authors.workspace = true
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[lib]
-proc-macro = true
-
-[features]
-default = ["smol"]
-smol = []
-tokio = []
-
-[dependencies]
-proc-macro2 = "1.0"
-quote = "1.0"
-syn = { version = "2.0", features = ["full"] }
-
-serde_json = "1.0.117"
diff --git a/jsonrpc/jsonrpc_macro/src/lib.rs b/jsonrpc/jsonrpc_macro/src/lib.rs
deleted file mode 100644
index ecca5b1..0000000
--- a/jsonrpc/jsonrpc_macro/src/lib.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-use proc_macro::TokenStream;
-use proc_macro2::{Ident, TokenStream as TokenStream2};
-use quote::quote;
-use syn::{parse_macro_input, spanned::Spanned, ImplItem, ItemImpl, Type};
-
-macro_rules! err {
- ($($tt:tt)*) => {
- return syn::Error::new($($tt)*).to_compile_error().into()
- };
-}
-
-#[proc_macro_attribute]
-pub fn rpc_impl(_attr: TokenStream, item: TokenStream) -> TokenStream {
- let mut methods: Vec<Ident> = vec![];
-
- let item2 = item.clone();
- let parsed_input = parse_macro_input!(item2 as ItemImpl);
-
- let self_ty = match *parsed_input.self_ty {
- Type::Path(p) => p,
- _ => err!(
- parsed_input.span(),
- "implementing the trait `RPCService` on this type is unsupported"
- ),
- };
-
- if parsed_input.items.is_empty() {
- err!(self_ty.span(), "At least one method should be implemented");
- }
-
- for item in parsed_input.items {
- match item {
- ImplItem::Fn(method) => {
- methods.push(method.sig.ident);
- }
- _ => err!(item.span(), "unexpected item"),
- }
- }
-
- let item2: TokenStream2 = item.into();
- let quoted = quote! {
- karyon_jsonrpc::impl_rpc_service!(#self_ty, #(#methods),*);
- #item2
- };
-
- quoted.into()
-}
-
-// TODO remove duplicate code
-#[proc_macro_attribute]
-pub fn rpc_pubsub_impl(_attr: TokenStream, item: TokenStream) -> TokenStream {
- let mut methods: Vec<Ident> = vec![];
-
- let item2 = item.clone();
- let parsed_input = parse_macro_input!(item2 as ItemImpl);
-
- let self_ty = match *parsed_input.self_ty {
- Type::Path(p) => p,
- _ => err!(
- parsed_input.span(),
- "implementing the trait `RPCService` on this type is unsupported"
- ),
- };
-
- if parsed_input.items.is_empty() {
- err!(self_ty.span(), "At least one method should be implemented");
- }
-
- for item in parsed_input.items {
- match item {
- ImplItem::Fn(method) => {
- methods.push(method.sig.ident);
- }
- _ => err!(item.span(), "unexpected item"),
- }
- }
-
- let item2: TokenStream2 = item.into();
- let quoted = quote! {
- karyon_jsonrpc::impl_pubsub_rpc_service!(#self_ty, #(#methods),*);
- #item2
- };
-
- quoted.into()
-}