From 7c17e9b07a08b85a50e6cefce4275b140002a3d5 Mon Sep 17 00:00:00 2001
From: jphppd <59113286+jphppd@users.noreply.github.com>
Date: Fri, 6 Nov 2026 19:13:38 +0100
Subject: [PATCH 1/5] run cargo fmt
---
derive/src/catalyst.rs | 6 ++----
derive/src/filler.rs | 10 ++++++++--
derive/src/patch.rs | 10 ++++++++--
lib/src/box.rs | 1 -
lib/src/traits.rs | 12 ++++++++++--
5 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/derive/src/catalyst.rs b/derive/src/catalyst.rs
index 8826f4a..527ce07 100644
--- a/derive/src/catalyst.rs
+++ b/derive/src/catalyst.rs
@@ -381,8 +381,7 @@ fn find_fields_from_src(src: &str, struct_name: &str) -> syn::Fields {
.split_once(':')
.expect("src attribute must be 'crate_name:/path/to/file.rs'");
- let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
- .expect("CARGO_MANIFEST_DIR is not set");
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not set");
let meta = cargo_metadata::MetadataCommand::new()
.manifest_path(std::path::Path::new(&manifest_dir).join("Cargo.toml"))
@@ -400,8 +399,7 @@ fn find_fields_from_src(src: &str, struct_name: &str) -> syn::Fields {
.parent()
.expect("manifest_path has no parent directory");
- let src_path = std::path::Path::new(pkg_dir.as_str())
- .join(rel_path.trim_start_matches('/'));
+ let src_path = std::path::Path::new(pkg_dir.as_str()).join(rel_path.trim_start_matches('/'));
let content = std::fs::read_to_string(&src_path)
.unwrap_or_else(|e| panic!("cannot read `{}`: {}", src_path.display(), e));
diff --git a/derive/src/filler.rs b/derive/src/filler.rs
index dda4b75..5b8dd7d 100644
--- a/derive/src/filler.rs
+++ b/derive/src/filler.rs
@@ -321,7 +321,11 @@ impl Filler {
self.#nesting_field_names.apply(filler.#nesting_field_names);
)*
};
- #[cfg(all(feature = "nesting", not(feature = "simple-nesting"), not(feature = "log")))]
+ #[cfg(all(
+ feature = "nesting",
+ not(feature = "simple-nesting"),
+ not(feature = "log")
+ ))]
let nesting_apply_section: TokenStream = quote! {
#(
self.#nesting_field_names.apply(filler.#nesting_field_names);
@@ -524,7 +528,9 @@ impl Filler {
}
#[cfg(not(feature = "log"))]
DEFAULT_LOG => {
- return Err(meta.error("`default_log` attribute requires the `log` feature"));
+ return Err(
+ meta.error("`default_log` attribute requires the `log` feature")
+ );
}
_ => {
return Err(meta.error(format_args!(
diff --git a/derive/src/patch.rs b/derive/src/patch.rs
index 9a3d580..68a57db 100644
--- a/derive/src/patch.rs
+++ b/derive/src/patch.rs
@@ -845,7 +845,11 @@ impl Patch {
self.#nesting_field_names.apply(patch.#nesting_field_names);
)*
};
- #[cfg(all(feature = "nesting", not(feature = "simple-nesting"), not(feature = "log")))]
+ #[cfg(all(
+ feature = "nesting",
+ not(feature = "simple-nesting"),
+ not(feature = "log")
+ ))]
let nesting_apply_section: TokenStream = quote! {
#(
self.#nesting_field_names.apply(patch.#nesting_field_names);
@@ -1368,7 +1372,9 @@ impl Patch {
}
#[cfg(not(feature = "log"))]
DEFAULT_LOG => {
- return Err(meta.error("`default_log` attribute requires the `log` feature"));
+ return Err(
+ meta.error("`default_log` attribute requires the `log` feature")
+ );
}
_ => {
return Err(meta.error(format_args!(
diff --git a/lib/src/box.rs b/lib/src/box.rs
index ee5353f..6bb6093 100644
--- a/lib/src/box.rs
+++ b/lib/src/box.rs
@@ -2,4 +2,3 @@
extern crate alloc;
pub use alloc::boxed::Box;
-
diff --git a/lib/src/traits.rs b/lib/src/traits.rs
index b553d6d..75969a1 100644
--- a/lib/src/traits.rs
+++ b/lib/src/traits.rs
@@ -238,7 +238,11 @@ pub trait Patch
{
self.apply(patch);
}
- #[cfg(all(feature = "log", not(feature = "nesting"), not(feature = "simple-nesting")))]
+ #[cfg(all(
+ feature = "log",
+ not(feature = "nesting"),
+ not(feature = "simple-nesting")
+ ))]
fn apply_with_log(&mut self, patch: P, _log: F) {
self.apply(patch);
}
@@ -304,7 +308,11 @@ pub trait Filler {
self.apply(filler);
}
- #[cfg(all(feature = "log", not(feature = "nesting"), not(feature = "simple-nesting")))]
+ #[cfg(all(
+ feature = "log",
+ not(feature = "nesting"),
+ not(feature = "simple-nesting")
+ ))]
fn apply_with_log(&mut self, filler: F, _log: L) {
self.apply(filler);
}
From a10640da98b8d09008dca64119adc80101e8e01d Mon Sep 17 00:00:00 2001
From: jphppd <59113286+jphppd@users.noreply.github.com>
Date: Fri, 6 Nov 2026 19:51:40 +0100
Subject: [PATCH 2/5] fix cargo clippy warnings
---
derive/src/catalyst.rs | 23 ++++++++++-------------
derive/src/filler.rs | 2 +-
derive/src/patch.rs | 6 +++---
lib/src/lib.rs | 2 ++
4 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/derive/src/catalyst.rs b/derive/src/catalyst.rs
index 527ce07..3666ce4 100644
--- a/derive/src/catalyst.rs
+++ b/derive/src/catalyst.rs
@@ -56,7 +56,7 @@ impl Catalyst {
} = self;
let substrate_name: Ident = {
- let lit = LitStr::new(&bind, Span::call_site());
+ let lit = LitStr::new(bind, Span::call_site());
lit.parse()?
};
@@ -355,7 +355,7 @@ impl Catalyst {
));
}
let complex_struct_name = name.unwrap_or({
- let ts = TokenStream::from_str(&format!("{}Complex", &ident,)).unwrap();
+ let ts = TokenStream::from_str(&format!("{}Complex", ident)).unwrap();
let lit = LitStr::new(&ts.to_string(), Span::call_site());
lit.parse()?
});
@@ -445,13 +445,13 @@ impl Field {
}
if keep_field_attribute {
- if attrs.len() > 0 {
+ if !attrs.is_empty() {
// from substrate: filter out excluded attribute namespaces
let filtered_attrs: Vec<&Attribute> = attrs
.iter()
.filter(|a| {
let path = a.path().to_token_stream().to_string();
- !exclude_field_attributes.iter().any(|e| path == *e)
+ !exclude_field_attributes.contains(&path)
})
.collect();
Ok(quote! {
@@ -527,15 +527,12 @@ impl Field {
}
let _ = attr.parse_nested_meta(|meta| {
let path = meta.path.to_string();
- match path.as_str() {
- ATTRIBUTE => {
- // #[complex(attribute(serde(default))]
- let content;
- parenthesized!(content in meta.input);
- let attribute: TokenStream = content.parse()?;
- attributes.push(attribute);
- }
- _ => {}
+ if path.as_str() == ATTRIBUTE {
+ // #[complex(attribute(serde(default))]
+ let content;
+ parenthesized!(content in meta.input);
+ let attribute: TokenStream = content.parse()?;
+ attributes.push(attribute);
}
Ok(())
});
diff --git a/derive/src/filler.rs b/derive/src/filler.rs
index 5b8dd7d..1c4f508 100644
--- a/derive/src/filler.rs
+++ b/derive/src/filler.rs
@@ -548,7 +548,7 @@ impl Filler {
fields.push(f);
}
}
- let ts = TokenStream::from_str(&format!("{}Filler", &ident,)).unwrap();
+ let ts = TokenStream::from_str(&format!("{}Filler", ident)).unwrap();
let lit = LitStr::new(&ts.to_string(), Span::call_site());
let filler_struct_name = lit.parse()?;
diff --git a/derive/src/patch.rs b/derive/src/patch.rs
index 68a57db..c9dc815 100644
--- a/derive/src/patch.rs
+++ b/derive/src/patch.rs
@@ -1396,7 +1396,7 @@ impl Patch {
Ok(Patch {
visibility: vis,
patch_struct_name: name.unwrap_or({
- let ts = TokenStream::from_str(&format!("{}Patch", &ident,)).unwrap();
+ let ts = TokenStream::from_str(&format!("{}Patch", ident)).unwrap();
let lit = LitStr::new(&ts.to_string(), Span::call_site());
lit.parse()?
}),
@@ -1451,7 +1451,7 @@ impl Field {
if *nesting {
// TODO handle rename
let patch_type = syn::Ident::new(
- &format!("{}Patch", &ty.to_token_stream()),
+ &format!("{}Patch", ty.to_token_stream()),
Span::call_site(),
);
Ok(quote! {
@@ -1489,7 +1489,7 @@ impl Field {
if *nesting {
// TODO handle rename
let patch_type = syn::Ident::new(
- &format!("{}Patch", &ty.to_token_stream()),
+ &format!("{}Patch", ty.to_token_stream()),
Span::call_site(),
);
Ok(quote! {
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index ea2ee22..740e61d 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -407,6 +407,7 @@ mod tests {
fn test_add_patches() {
#[derive(Patch)]
#[patch(attribute(derive(Debug, PartialEq)))]
+ #[allow(dead_code, reason = "used for the test of derive(Patch)")]
struct Item {
field: u32,
other: String,
@@ -435,6 +436,7 @@ mod tests {
#[should_panic]
fn test_add_conflict_patches_panic() {
#[derive(Patch, Debug, PartialEq)]
+ #[allow(dead_code, reason = "used for the test of derive(Patch)")]
struct Item {
field: u32,
}
From db97075bded5eff98879854c6ea19c2dc4eae7f0 Mon Sep 17 00:00:00 2001
From: jphppd <59113286+jphppd@users.noreply.github.com>
Date: Fri, 6 Nov 2026 20:21:09 +0100
Subject: [PATCH 3/5] use string interpolation in format!
---
derive/src/catalyst.rs | 2 +-
derive/src/filler.rs | 2 +-
derive/src/lib.rs | 12 +++---------
derive/src/patch.rs | 2 +-
docs/logs.md | 6 +++---
examples/filler-examples/examples/log.rs | 2 +-
examples/patch-examples/examples/log.rs | 6 +++---
examples/patch-examples/examples/op.rs | 2 +-
lib/src/traits.rs | 10 +++++-----
9 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/derive/src/catalyst.rs b/derive/src/catalyst.rs
index 3666ce4..77539d5 100644
--- a/derive/src/catalyst.rs
+++ b/derive/src/catalyst.rs
@@ -355,7 +355,7 @@ impl Catalyst {
));
}
let complex_struct_name = name.unwrap_or({
- let ts = TokenStream::from_str(&format!("{}Complex", ident)).unwrap();
+ let ts = TokenStream::from_str(&format!("{ident}Complex")).unwrap();
let lit = LitStr::new(&ts.to_string(), Span::call_site());
lit.parse()?
});
diff --git a/derive/src/filler.rs b/derive/src/filler.rs
index 1c4f508..7d77752 100644
--- a/derive/src/filler.rs
+++ b/derive/src/filler.rs
@@ -548,7 +548,7 @@ impl Filler {
fields.push(f);
}
}
- let ts = TokenStream::from_str(&format!("{}Filler", ident)).unwrap();
+ let ts = TokenStream::from_str(&format!("{ident}Filler")).unwrap();
let lit = LitStr::new(&ts.to_string(), Span::call_site());
let filler_struct_name = lit.parse()?;
diff --git a/derive/src/lib.rs b/derive/src/lib.rs
index f66f4ae..9ce37d5 100644
--- a/derive/src/lib.rs
+++ b/derive/src/lib.rs
@@ -73,10 +73,7 @@ fn get_lit(attr_name: String, meta: &ParseNestedMeta) -> syn::Result