Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syn and darling in yerpc-derive #62

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions yerpc-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.37"
quote = "1.0.18"
syn = { version = "1.0.91", features = ["full", "parsing", "printing"] }
darling = "0.14.0"
syn = { version = "2.0.68", features = ["full", "parsing", "printing"] }
darling = "0.20.0"
convert_case = "0.5.0"

[features]
Expand Down
11 changes: 8 additions & 3 deletions yerpc-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#![warn(missing_debug_implementations, missing_docs, clippy::wildcard_imports)]

extern crate darling;
use darling::ast::NestedMeta;
use darling::{FromAttributes, FromMeta};
#[cfg(feature = "openrpc")]
use openrpc::generate_openrpc_generator;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, AttributeArgs, Item};
use syn::{parse_macro_input, Item};

#[cfg(feature = "openrpc")]
mod openrpc;
Expand Down Expand Up @@ -43,10 +44,14 @@
let item = parse_macro_input!(tokens as Item);
match &item {
Item::Impl(input) => {
let attr_args = parse_macro_input!(attr as AttributeArgs);
let attr_args = match NestedMeta::parse_meta_list(attr.into()) {
Ok(v) => v,
Err(err) => return TokenStream::from(darling::Error::from(err).write_errors()),
};

let attr_args = match RootAttrArgs::from_list(&attr_args) {
Ok(args) => args,
Err(err) => return err.write_errors().into(),
Err(err) => return TokenStream::from(err.write_errors()),
};
if attr_args.openrpc_outdir.is_none() && attr_args.ts_outdir.is_none() {
return syn::Error::new_spanned(
Expand Down Expand Up @@ -112,7 +117,7 @@
name: Option<String>,
/// Make this a notification method. Notifications are received like method calls but cannot
/// return anything.
#[darling(default)]

Check failure on line 120 in yerpc-derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

if let can be simplified with `.unwrap_or_default()`
notification: bool,
/// Positional mode means that the parameters of the RPC call are expected to be a JSON array,
/// which will be parsed as a tuple of this function's arguments.
Expand Down
16 changes: 8 additions & 8 deletions yerpc-derive/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::MethodAttrArgs;
use darling::FromAttributes;
// use proc_macro2::Ident;
use syn::{FnArg, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Pat, ReturnType, Type};
use syn::{FnArg, Generics, Ident, ImplItem, ImplItemFn, ItemImpl, Pat, ReturnType, Type};

use crate::RootAttrArgs;

Expand All @@ -25,7 +24,7 @@ impl<'s> RpcInfo<'s> {
.items
.iter()
.filter_map(|item| {
if let ImplItem::Method(method) = item {
if let ImplItem::Fn(method) = item {
Some(RemoteProcedure::from_method(attr_args, method))
} else {
None
Expand Down Expand Up @@ -93,10 +92,11 @@ impl<'s> Input<'s> {
fn parse_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
let mut parts = vec![];
for attr in attrs {
let meta = attr.parse_meta().unwrap();
if let syn::Meta::NameValue(meta) = meta {
if let syn::Lit::Str(doc) = meta.lit {
parts.push(doc.value());
if let syn::Meta::NameValue(meta) = &attr.meta {
if let syn::Expr::Lit(expr_lit) = &meta.value {
if let syn::Lit::Str(lit_str) = &expr_lit.lit {
parts.push(lit_str.value());
}
}
}
}
Expand All @@ -108,7 +108,7 @@ fn parse_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
}

impl<'s> RemoteProcedure<'s> {
pub fn from_method(root_attr_args: &RootAttrArgs, method: &'s ImplItemMethod) -> Self {
pub fn from_method(root_attr_args: &RootAttrArgs, method: &'s ImplItemFn) -> Self {
let args = MethodAttrArgs::from_attributes(&method.attrs).unwrap_or_default();
let name = args.name.unwrap_or_else(|| method.sig.ident.to_string());
let output = match &method.sig.output {
Expand Down
Loading