Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = [

[workspace.package]
authors = ["Antonio Yang <yanganto@gmail.com>"]
version = "0.14.0"
version = "0.14.1"
edition = "2021"
categories = ["development-tools"]
keywords = ["struct", "patch", "macro", "derive", "overlay"]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This crate provides the `Patch`, `Filler`, `Substrate`, `Catalyst` and `Complex`

- If any field in a `Patch` is `Some`, it overwrites the corresponding field when applied. Use `apply_with_log` to receive a callback for each field that is actually changed.
- If any field in the instance is empty (`None` or an empty collection), `Filler` will try to fill it. It supports `Option`, `Vec`, `VecDeque`, `LinkedList`, `HashMap`, `BTreeMap`, `HashSet`, `BTreeSet`, `BinaryHeap` fields, as well as custom types via `#[filler(extendable)]` and any type via `#[filler(empty_value = ...)]`.
- With the `catalyst` feature, `Substrate`, `Catalyst` and `Complex` traits with accompanying derive macros help you extend a struct with extra fields from another crate.
- With the `substrate` feature, the `Substrate` derive macro exposes field information so that other crates can access it. With the `catalyst` feature (which implies `substrate`), `Catalyst` and `Complex` derive macros help you extend a struct with extra fields from another crate.

This crate supports `no_std` — check the [no-std-examples](./no-std-examples).

Expand Down Expand Up @@ -264,7 +264,8 @@ This crate includes the following optional features:
- `none_as_default` *(optional)*: `T` needs to implement `Default`. When patching on `None`, it patches on a default instance. Mutually exclusive with `keep_none`.
- `keep_none` *(optional)*: when patching on `None`, it stays `None`. Mutually exclusive with `none_as_default`.
- `nesting` *(optional)*: allows a field to use `Patch` derive with the `#[patch(nesting)]` attribute.
- `catalyst` *(optional)*: enables the `Substrate`, `Catalyst`, and `Complex` derive macros for extending a struct with fields from another crate.
- `substrate` *(optional)*: enables the `Substrate` derive macro for exposing a struct's field layout so downstream crates can access it via `expose()` or source parsing.
- `catalyst` *(optional)*: enables the `Catalyst` and `Complex` derive macros for extending a struct with fields from another crate. Implies `substrate`.
- `unsafe` *(optional)*: uses `ManuallyDrop` + `ptr::read` / `MaybeUninit` + `ptr::write` in the generated `bind`, `decouple`, `__substrate_new`, and `__substrate_unpack` to avoid memory moves. Only meaningful with the `catalyst` feature.

[crates-badge]: https://img.shields.io/crates/v/struct-patch.svg
Expand Down
4 changes: 2 additions & 2 deletions complex-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ members = [
"catalyst-src",
]
[workspace.dependencies]
struct-patch = { path = "../lib", features = ["catalyst"] }
struct-patch = { path = "../lib" }

[workspace.package]
authors = ["Antonio Yang <yanganto@gmail.com>"]
version = "0.14.0"
version = "0.14.1"
edition = "2021"
categories = ["development-tools"]
keywords = ["struct", "patch", "macro", "derive", "overlay"]
Expand Down
2 changes: 1 addition & 1 deletion complex-example/catalyst-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description.workspace = true
rust-version.workspace = true

[dependencies]
struct-patch.workspace = true
struct-patch = { workspace = true, features = ["catalyst"] }
substrate = { path = "../substrate" }
serde = { version = "1", features = ["derive"] }
toml = "1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion complex-example/catalyst/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description.workspace = true
rust-version.workspace = true

[dependencies]
struct-patch.workspace = true
struct-patch = { workspace = true, features = ["catalyst"] }
substrate = { path = "../substrate" }
serde = { version = "1", features = ["derive"] }
toml = "1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion complex-example/substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description.workspace = true
rust-version.workspace = true

[dependencies]
struct-patch.workspace = true
struct-patch = { workspace = true, features = ["substrate"] }
serde = { version = "1", features = ["derive"] }

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ status = []
op = []
merge = []
nesting = []
catalyst = [ "syn-serde", "dep:cargo_metadata", "syn/full" ]
substrate = [ "syn-serde", "syn/full" ]
catalyst = [ "substrate", "dep:cargo_metadata" ]
unsafe = []
box = []

Expand Down
6 changes: 3 additions & 3 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ extern crate proc_macro;
mod catalyst;
mod filler;
mod patch;
#[cfg(feature = "catalyst")]
#[cfg(feature = "substrate")]
mod substrate;

#[cfg(feature = "catalyst")]
use catalyst::Catalyst;
use filler::Filler;
use patch::Patch;
#[cfg(feature = "catalyst")]
#[cfg(feature = "substrate")]
use substrate::Substrate;

use syn::meta::ParseNestedMeta;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn derive_filler(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
.into()
}

#[cfg(feature = "catalyst")]
#[cfg(feature = "substrate")]
#[proc_macro_derive(Substrate, attributes(substrate))]
pub fn derive_substrate(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
Substrate::from_ast(syn::parse_macro_input!(item as syn::DeriveInput))
Expand Down
8 changes: 6 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme.workspace = true
rust-version.workspace = true

[dependencies]
struct-patch-derive = { version = "=0.14.0", path = "../derive" }
struct-patch-derive = { version = "=0.14.1", path = "../derive" }

[dev-dependencies]
serde_json = "1.0"
Expand Down Expand Up @@ -43,8 +43,12 @@ nesting = [
]
none_as_default = ["option"]
keep_none = ["option"]
substrate = [
"struct-patch-derive/substrate"
]
catalyst = [
"struct-patch-derive/catalyst"
"struct-patch-derive/catalyst",
"struct-patch-derive/substrate"
]
unsafe = [
"struct-patch-derive/unsafe"
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub use struct_patch_derive::Catalyst;
pub use struct_patch_derive::Filler;
#[doc(hidden)]
pub use struct_patch_derive::Patch;
#[cfg(feature = "catalyst")]
#[cfg(feature = "substrate")]
#[doc(hidden)]
pub use struct_patch_derive::Substrate;
pub mod r#box;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub trait Merge {
fn merge(self, other: Self) -> Self;
}

#[cfg(feature = "catalyst")]
#[cfg(feature = "substrate")]
/// A substrate struct that can expose the fields information thereof
pub trait Substrate {
fn expose_content() -> &'static str;
Expand Down
2 changes: 1 addition & 1 deletion no-std-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "no-std-examples"
authors = ["Antonio Yang <yanganto@gmail.com>"]
version = "0.14.0"
version = "0.14.1"
edition = "2021"
license = "MIT"

Expand Down