diff options
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | trakt-macros/Cargo.toml | 2 | ||||
-rw-r--r-- | trakt-macros/src/lib.rs | 11 | ||||
-rw-r--r-- | trakt-macros/src/paginated.rs | 38 | ||||
-rw-r--r-- | trakt-rs/Cargo.toml | 2 |
5 files changed, 36 insertions, 20 deletions
@@ -1,3 +1,6 @@ [workspace] members = ["trakt-rs", "trakt-macros"] resolver = "2" + +[workspace.dependencies] +trakt-macros = { path = "trakt-macros", version = "0.1.0" } diff --git a/trakt-macros/Cargo.toml b/trakt-macros/Cargo.toml index 98988cf..59df0f7 100644 --- a/trakt-macros/Cargo.toml +++ b/trakt-macros/Cargo.toml @@ -9,6 +9,6 @@ proc-macro = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -proc-macro2 = "1.0.78" +proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["full"] } diff --git a/trakt-macros/src/lib.rs b/trakt-macros/src/lib.rs index 5dcb4e7..6eddfc0 100644 --- a/trakt-macros/src/lib.rs +++ b/trakt-macros/src/lib.rs @@ -1,3 +1,14 @@ +#![warn( + clippy::pedantic, + clippy::nursery, + clippy::as_underscore, + clippy::clone_on_ref_ptr, + clippy::format_push_string, + clippy::mod_module_files, + clippy::str_to_string +)] +#![allow(clippy::module_name_repetitions)] + mod paginated; mod request; diff --git a/trakt-macros/src/paginated.rs b/trakt-macros/src/paginated.rs index d9aa2fd..d2cc8b5 100644 --- a/trakt-macros/src/paginated.rs +++ b/trakt-macros/src/paginated.rs @@ -78,14 +78,15 @@ fn handle_field_attrs(input: &DeriveInput) -> syn::Result<&syn::Field> { } } - if let Some(ret) = ret { - Ok(ret) - } else { - Err(syn::Error::new( - Span::call_site(), - "missing #[trakt(pagination)] attribute", - )) - } + ret.map_or_else( + || { + Err(syn::Error::new( + Span::call_site(), + "missing #[trakt(pagination)] attribute", + )) + }, + Ok, + ) } /// Extracts the inner type of `PaginationResponse<T>` type. @@ -119,17 +120,18 @@ fn extract_item(tp: &syn::Type) -> syn::Result<&syn::Type> { if let syn::GenericArgument::Type(t) = &args[0] { tp = Some(t); break; - } else { - return Err(syn::Error::new(args.span(), "expected a type argument")); } - } - if let Some(tp) = tp { - Ok(tp) - } else { - Err(syn::Error::new( - tp.span(), - "expected a PaginationResponse type", - )) + return Err(syn::Error::new(args.span(), "expected a type argument")); } + + tp.map_or_else( + || { + Err(syn::Error::new( + tp.span(), + "expected a PaginationResponse type", + )) + }, + Ok, + ) } diff --git a/trakt-rs/Cargo.toml b/trakt-rs/Cargo.toml index 91b8c42..39eefb0 100644 --- a/trakt-rs/Cargo.toml +++ b/trakt-rs/Cargo.toml @@ -17,4 +17,4 @@ serde_json = "1" serde_urlencoded = "0.7" thiserror = "1" time = { version = "0.3", features = ["formatting", "parsing", "serde"] } -trakt-macros = { path = "../trakt-macros" } +trakt-macros = { workspace = true } |