(result.to_token_stream().unwrap()).unwrap();
}
}
diff --git a/docs/logs.md b/docs/logs.md
index 7702237..2a8d819 100644
--- a/docs/logs.md
+++ b/docs/logs.md
@@ -86,7 +86,7 @@ fn my_log(prefixes: &[&str], field: &str) {
let path = if prefixes.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefixes.join("."), field)
+ format!("{}.{field}", prefixes.join("."))
};
println!("patched: {path}");
}
@@ -125,7 +125,7 @@ fn log_field(prefix: &str, field: &str) {
let path = if prefix.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefix, field)
+ format!("{prefix}.{field}")
};
println!("patched: {path}");
}
@@ -163,7 +163,7 @@ item.apply_with_log(patch, |prefix, field| {
let path = if prefix.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefix, field)
+ format!("{prefix}.{field}")
};
println!("patched: {path}");
});
diff --git a/examples/filler-examples/examples/log.rs b/examples/filler-examples/examples/log.rs
index e83b572..6aa8015 100644
--- a/examples/filler-examples/examples/log.rs
+++ b/examples/filler-examples/examples/log.rs
@@ -13,7 +13,7 @@ fn log_filler_field(prefixes: &[&str], field: &str) {
let path = if prefixes.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefixes.join("."), field)
+ format!("{}.{field}", prefixes.join("."))
};
println!("[default_log] filler field: {path}");
}
diff --git a/examples/patch-examples/Cargo.toml b/examples/patch-examples/Cargo.toml
index 0dfcda9..e8a55bb 100644
--- a/examples/patch-examples/Cargo.toml
+++ b/examples/patch-examples/Cargo.toml
@@ -13,6 +13,7 @@ serde_with = "3.9.0"
toml = "1.1.2"
humantime-serde = "1.1.1"
clap = { version = "4.4.7", features = ["derive"] }
+schemars = "1.2.3"
[features]
default = ["status", "op"]
@@ -30,3 +31,7 @@ keep_none = ["option", "struct-patch/keep_none"]
[[example]]
name = "box"
required-features = ["box"]
+
+[[example]]
+name = "jsonschema"
+required-features = ["struct-patch/copy_doc"]
\ No newline at end of file
diff --git a/examples/patch-examples/examples/jsonschema.rs b/examples/patch-examples/examples/jsonschema.rs
new file mode 100644
index 0000000..4f4c0c7
--- /dev/null
+++ b/examples/patch-examples/examples/jsonschema.rs
@@ -0,0 +1,48 @@
+use schemars::{schema_for, JsonSchema};
+use struct_patch::Patch;
+
+/// The documentation for my structure.
+#[derive(JsonSchema, Patch)]
+#[patch(attribute(derive(JsonSchema)))]
+struct MyStruct {
+ /// The documentation for my field.
+ my_field: bool,
+}
+
+fn main() {
+ let schema = schema_for!(MyStruct);
+ assert_eq!(schema.get("title").unwrap(), "MyStruct");
+ assert_eq!(
+ schema.get("description").unwrap(),
+ "The documentation for my structure."
+ );
+ assert_eq!(
+ schema
+ .get("properties")
+ .unwrap()
+ .get("my_field")
+ .unwrap()
+ .get("description")
+ .unwrap(),
+ "The documentation for my field."
+ );
+ dbg!(schema);
+
+ let schema = schema_for!(MyStructPatch);
+ assert_eq!(schema.get("title").unwrap(), "MyStructPatch");
+ assert_eq!(
+ schema.get("description").unwrap(),
+ "The documentation for my structure."
+ );
+ assert_eq!(
+ schema
+ .get("properties")
+ .unwrap()
+ .get("my_field")
+ .unwrap()
+ .get("description")
+ .unwrap(),
+ "The documentation for my field."
+ );
+ dbg!(schema);
+}
diff --git a/examples/patch-examples/examples/log.rs b/examples/patch-examples/examples/log.rs
index 2a9f34d..1b0d92a 100644
--- a/examples/patch-examples/examples/log.rs
+++ b/examples/patch-examples/examples/log.rs
@@ -10,7 +10,7 @@ fn log_patch_field(prefixes: &[&str], field: &str) {
let path = if prefixes.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefixes.join("."), field)
+ format!("{}.{field}", prefixes.join("."))
};
println!("[default_log] patch field: {path}");
}
@@ -56,10 +56,7 @@ fn main() {
// [default_log] patch field: host
// [default_log] patch field: port
- println!(
- "host={}, port={}",
- config.host, config.port
- );
+ println!("host={}, port={}", config.host, config.port);
println!("\n--- Patch: apply_with_log() with custom format ---");
config.apply_with_log(
@@ -74,10 +71,7 @@ fn main() {
// Prints:
// [custom_log] patch field port was updated
- println!(
- "host={}, port={}",
- config.host, config.port
- );
+ println!("host={}, port={}", config.host, config.port);
}
#[cfg(feature = "nesting")]
@@ -117,7 +111,7 @@ fn main() {
let path = if prefixes.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefixes.join("."), field)
+ format!("{}.{field}", prefixes.join("."))
};
println!("[custom_log] patch field: '{path}'");
},
@@ -177,7 +171,7 @@ fn main() {
let path = if prefixes.is_empty() {
field.to_string()
} else {
- format!("{}.{}", prefixes.join("."), field)
+ format!("{}.{field}", prefixes.join("."))
};
println!("[custom_log] patch field: '{path}'");
},
@@ -188,8 +182,6 @@ fn main() {
println!(
"config.port={}, config.logging.level={}, config.logging.format={}",
- server4.config.port,
- server4.config.logging.level,
- server4.config.logging.format
+ server4.config.port, server4.config.logging.level, server4.config.logging.format
);
}
diff --git a/examples/patch-examples/examples/op.rs b/examples/patch-examples/examples/op.rs
index 1433d18..df9c8c4 100644
--- a/examples/patch-examples/examples/op.rs
+++ b/examples/patch-examples/examples/op.rs
@@ -1,6 +1,6 @@
#[cfg(feature = "op")]
fn str_concat(a: String, b: String) -> String {
- format!("{}, {}", a, b)
+ format!("{a}, {b}")
}
#[cfg(feature = "op")]
diff --git a/lib/Cargo.toml b/lib/Cargo.toml
index 8bd65eb..70a224a 100644
--- a/lib/Cargo.toml
+++ b/lib/Cargo.toml
@@ -55,4 +55,6 @@ catalyst = [
unsafe = [
"struct-patch-derive/unsafe"
]
-
+copy_doc = [
+ "struct-patch-derive/copy_doc"
+]
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/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,
}
diff --git a/lib/src/traits.rs b/lib/src/traits.rs
index b553d6d..ef66cc8 100644
--- a/lib/src/traits.rs
+++ b/lib/src/traits.rs
@@ -86,7 +86,7 @@
/// let path = if prefixes.is_empty() {
/// field.to_string()
/// } else {
-/// format!("{}.{}", prefixes.join("."), field)
+/// format!("{}.{field}", prefixes.join("."))
/// };
/// println!("patched: {path}");
/// }
@@ -95,7 +95,7 @@
/// let path = if prefix.is_empty() {
/// field.to_string()
/// } else {
-/// format!("{}.{}", prefix, field)
+/// format!("{prefix}.{field}")
/// };
/// println!("patched: {path}");
/// }
@@ -208,7 +208,7 @@ pub trait Patch {
/// let path = if prefix.is_empty() {
/// field.to_string()
/// } else {
- /// format!("{}.{}", prefix, field)
+ /// format!("{prefix}.{field}")
/// };
/// patched_fields.push(path);
/// });
@@ -217,7 +217,7 @@ pub trait Patch
{
/// let path = if prefixes.is_empty() {
/// field.to_string()
/// } else {
- /// format!("{}.{}", prefixes.join("."), field)
+ /// format!("{}.{field}", prefixes.join("."))
/// };
/// patched_fields.push(path);
/// });
@@ -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);
}
@@ -282,7 +286,7 @@ pub trait Filler {
/// let path = if prefixes.is_empty() {
/// field.to_string()
/// } else {
- /// format!("{}.{}", prefixes.join("."), field)
+ /// format!("{}.{field}", prefixes.join("."))
/// };
/// filled_fields.push(path);
/// });
@@ -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);
}