|
18 | 18 | //! # Usage
|
19 | 19 | //!
|
20 | 20 | //! ```rust
|
21 |
| -//! # #[cfg(feature = "std")] { |
| 21 | +//! # #[cfg(all(feature = "std", feature = "derive"))] { |
22 | 22 | //! use daft::{Diffable, Leaf};
|
23 | 23 | //!
|
24 | 24 | //! // Annotate your struct with `#[derive(Diffable)]`:
|
|
94 | 94 | //! assert_eq!(diff.before, Some(&1));
|
95 | 95 | //! assert_eq!(diff.after, Some(&2));
|
96 | 96 | //!
|
| 97 | +//! # #[cfg(feature = "derive")] { |
97 | 98 | //! // Automatically derived enums also use Leaf:
|
98 | 99 | //! #[derive(Debug, PartialEq, Eq, Diffable)]
|
99 | 100 | //! enum MyEnum {
|
|
107 | 108 | //! let diff: Leaf<&MyEnum> = before.diff(&after);
|
108 | 109 | //! assert_eq!(diff.before, &before);
|
109 | 110 | //! assert_eq!(diff.after, &after);
|
| 111 | +//! # } |
110 | 112 | //! ```
|
111 | 113 | //!
|
112 | 114 | //! Vectors use `Leaf` as well:
|
|
267 | 269 | //! Tuple-like structs produce tuple-like diff structs:
|
268 | 270 | //!
|
269 | 271 | //! ```rust
|
270 |
| -//! # #[cfg(feature = "std")] { |
| 272 | +//! # #[cfg(all(feature = "std", feature = "derive"))] { |
271 | 273 | //! use daft::Diffable;
|
272 | 274 | //! use std::collections::BTreeMap;
|
273 | 275 | //!
|
|
288 | 290 | //! An example with `#[daft(leaf)]` on **structs**:
|
289 | 291 | //!
|
290 | 292 | //! ```rust
|
| 293 | +//! # #[cfg(feature = "derive")] { |
291 | 294 | //! use daft::{Diffable, Leaf};
|
292 | 295 | //!
|
293 | 296 | //! #[derive(Diffable)]
|
|
302 | 305 | //!
|
303 | 306 | //! assert_eq!(diff.before.a, 1);
|
304 | 307 | //! assert_eq!(diff.after.a, 2);
|
| 308 | +//! # } |
305 | 309 | //! ```
|
306 | 310 | //!
|
307 | 311 | //! An example with `#[daft(leaf)]` on **struct fields**:
|
308 | 312 | //!
|
309 | 313 | //! ```rust
|
| 314 | +//! # #[cfg(feature = "derive")] { |
310 | 315 | //! use daft::{Diffable, Leaf};
|
311 | 316 | //!
|
312 | 317 | //! // A simple struct that implements Diffable.
|
|
353 | 358 | //!
|
354 | 359 | //! // `PlainStruct` can also be compared even though it doesn't implement `Diffable`.
|
355 | 360 | //! assert_eq!(diff.plain, Leaf { before: &PlainStruct(1), after: &PlainStruct(2) });
|
| 361 | +//! # } |
356 | 362 | //! ```
|
357 | 363 | //!
|
358 | 364 | //! ### Custom diff types
|
|
364 | 370 | //!
|
365 | 371 | //! ### Example
|
366 | 372 | //!
|
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: |
368 | 375 | //!
|
369 | 376 | //! ```rust
|
370 | 377 | //! # #[cfg(feature = "std")] {
|
|
400 | 407 | //! ### Example
|
401 | 408 | //!
|
402 | 409 | //! ```rust
|
| 410 | +//! # #[cfg(feature = "derive")] { |
403 | 411 | //! use daft::Diffable;
|
404 | 412 | //!
|
405 | 413 | //! #[derive(Diffable)]
|
|
417 | 425 | //! b: T::Diff<'daft>,
|
418 | 426 | //! }
|
419 | 427 | //! # */
|
| 428 | +//! # } |
420 | 429 | //! ```
|
421 | 430 | //!
|
422 | 431 | //! # Optional features
|
423 | 432 | //!
|
| 433 | +//! * `derive`: Enable the `Diffable` derive macro: **disabled** by default. |
| 434 | +//! |
424 | 435 | //! Implementations for standard library types, all **enabled** by default:
|
425 | 436 | //!
|
426 | 437 | //! * `alloc`: Enable diffing for types from the [`alloc`] crate.
|
@@ -507,6 +518,7 @@ pub use alloc_impls::*;
|
507 | 518 | /// diff.
|
508 | 519 | ///
|
509 | 520 | /// For more information, see the [crate-level documentation](crate).
|
| 521 | +#[cfg(feature = "derive")] |
510 | 522 | pub use daft_derive::Diffable;
|
511 | 523 | pub use diffable::*;
|
512 | 524 | pub use leaf::*;
|
|
0 commit comments