Skip to content

Commit 6e0af00

Browse files
authored
[16/n] add a derive feature
The derive macro isn't necessary for functionality, so some users might want to turn it off. Add it as a feature. Also group together third-party implementations so we only test 18 combinations rather than 65. Reviewers: andrewjstone Reviewed By: andrewjstone Pull Request: #47
1 parent 6ddfef1 commit 6e0af00

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Justfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ help:
66

77
# Run `cargo hack --feature-powerset` on crates
88
powerset *args:
9-
cargo hack --feature-powerset --workspace {{args}}
9+
# Group third-party implementation features to avoid a full combinatorial
10+
# explosion -- we assume that they build independent of each other.
11+
cargo hack --feature-powerset --workspace {{args}} --group-features newtype-uuid1,oxnet01,uuid1 --ignore-unknown-features
1012

1113
# Build docs for crates and direct dependencies
1214
rustdoc *args:

daft-derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ quote.workspace = true
2020
syn = { workspace = true, features = ["full", "visit"] }
2121

2222
[dev-dependencies]
23-
daft.workspace = true
23+
daft = { workspace = true, features = ["derive"] }
2424
datatest-stable.workspace = true
2525
expectorate.workspace = true
2626
prettyplease.workspace = true

daft/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license.workspace = true
1212
workspace = true
1313

1414
[dependencies]
15-
daft-derive.workspace = true
15+
daft-derive = { workspace = true, optional = true }
1616
newtype-uuid = { workspace = true, optional = true }
1717
oxnet = { workspace = true, optional = true }
1818
paste.workspace = true
@@ -22,6 +22,7 @@ uuid = { workspace = true, optional = true, features = ["v4"] }
2222
default = ["std"]
2323
std = ["alloc"]
2424
alloc = []
25+
derive = ["dep:daft-derive"]
2526
newtype-uuid1 = ["dep:newtype-uuid"]
2627
oxnet01 = ["dep:oxnet"]
2728
uuid1 = ["dep:uuid"]

daft/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ diff types directly.
356356

357357
#### Example
358358

359-
Some structs like identifiers should be treated as leaf nodes:
359+
Some structs like identifiers should be treated as leaf nodes. This can be
360+
implemented via `#[daft(leaf)]`, but also manually:
360361

361362
````rust
362363
use daft::{Diffable, Leaf};
@@ -409,6 +410,8 @@ struct BorrowedDataDiff<'daft, 'a: 'daft, 'b: 'daft, T: ?Sized + 'daft> {
409410

410411
## Optional features
411412

413+
* `derive`: Enable the `Diffable` derive macro: **disabled** by default.
414+
412415
Implementations for standard library types, all **enabled** by default:
413416

414417
* `alloc`: Enable diffing for types from the [`alloc`](https://doc.rust-lang.org/nightly/alloc/index.html) crate.

daft/src/lib.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! # Usage
1919
//!
2020
//! ```rust
21-
//! # #[cfg(feature = "std")] {
21+
//! # #[cfg(all(feature = "std", feature = "derive"))] {
2222
//! use daft::{Diffable, Leaf};
2323
//!
2424
//! // Annotate your struct with `#[derive(Diffable)]`:
@@ -94,6 +94,7 @@
9494
//! assert_eq!(diff.before, Some(&1));
9595
//! assert_eq!(diff.after, Some(&2));
9696
//!
97+
//! # #[cfg(feature = "derive")] {
9798
//! // Automatically derived enums also use Leaf:
9899
//! #[derive(Debug, PartialEq, Eq, Diffable)]
99100
//! enum MyEnum {
@@ -107,6 +108,7 @@
107108
//! let diff: Leaf<&MyEnum> = before.diff(&after);
108109
//! assert_eq!(diff.before, &before);
109110
//! assert_eq!(diff.after, &after);
111+
//! # }
110112
//! ```
111113
//!
112114
//! Vectors use `Leaf` as well:
@@ -267,7 +269,7 @@
267269
//! Tuple-like structs produce tuple-like diff structs:
268270
//!
269271
//! ```rust
270-
//! # #[cfg(feature = "std")] {
272+
//! # #[cfg(all(feature = "std", feature = "derive"))] {
271273
//! use daft::Diffable;
272274
//! use std::collections::BTreeMap;
273275
//!
@@ -288,6 +290,7 @@
288290
//! An example with `#[daft(leaf)]` on **structs**:
289291
//!
290292
//! ```rust
293+
//! # #[cfg(feature = "derive")] {
291294
//! use daft::{Diffable, Leaf};
292295
//!
293296
//! #[derive(Diffable)]
@@ -302,11 +305,13 @@
302305
//!
303306
//! assert_eq!(diff.before.a, 1);
304307
//! assert_eq!(diff.after.a, 2);
308+
//! # }
305309
//! ```
306310
//!
307311
//! An example with `#[daft(leaf)]` on **struct fields**:
308312
//!
309313
//! ```rust
314+
//! # #[cfg(feature = "derive")] {
310315
//! use daft::{Diffable, Leaf};
311316
//!
312317
//! // A simple struct that implements Diffable.
@@ -353,6 +358,7 @@
353358
//!
354359
//! // `PlainStruct` can also be compared even though it doesn't implement `Diffable`.
355360
//! assert_eq!(diff.plain, Leaf { before: &PlainStruct(1), after: &PlainStruct(2) });
361+
//! # }
356362
//! ```
357363
//!
358364
//! ### Custom diff types
@@ -364,7 +370,8 @@
364370
//!
365371
//! ### Example
366372
//!
367-
//! Some structs like identifiers should be treated as leaf nodes:
373+
//! Some structs like identifiers should be treated as leaf nodes. This can be
374+
//! implemented via `#[daft(leaf)]`, but also manually:
368375
//!
369376
//! ```rust
370377
//! # #[cfg(feature = "std")] {
@@ -400,6 +407,7 @@
400407
//! ### Example
401408
//!
402409
//! ```rust
410+
//! # #[cfg(feature = "derive")] {
403411
//! use daft::Diffable;
404412
//!
405413
//! #[derive(Diffable)]
@@ -417,10 +425,13 @@
417425
//! b: T::Diff<'daft>,
418426
//! }
419427
//! # */
428+
//! # }
420429
//! ```
421430
//!
422431
//! # Optional features
423432
//!
433+
//! * `derive`: Enable the `Diffable` derive macro: **disabled** by default.
434+
//!
424435
//! Implementations for standard library types, all **enabled** by default:
425436
//!
426437
//! * `alloc`: Enable diffing for types from the [`alloc`] crate.
@@ -507,6 +518,7 @@ pub use alloc_impls::*;
507518
/// diff.
508519
///
509520
/// For more information, see the [crate-level documentation](crate).
521+
#[cfg(feature = "derive")]
510522
pub use daft_derive::Diffable;
511523
pub use diffable::*;
512524
pub use leaf::*;

0 commit comments

Comments
 (0)