|
25 | 25 | //! as opposed to std's derives, which would only implement these traits with |
26 | 26 | //! `T: Trait` bound to the corresponding trait. |
27 | 27 | //! |
| 28 | +//! Multiple `derive_where` attributes can be added to an item, but only the |
| 29 | +//! first one should use any path qualifications. Otherwise helper attributes |
| 30 | +//! won't be applied to any but the first `derive_where` attribute on the item. |
| 31 | +//! |
| 32 | +//! ``` |
| 33 | +//! # use std::marker::PhantomData; |
| 34 | +//! #[derive_where::derive_where(Clone, Debug; T)] |
| 35 | +//! #[derive_where(PartialEq)] |
| 36 | +//! struct Example1<T, U> { |
| 37 | +//! a: u8, |
| 38 | +//! #[derive_where(skip)] |
| 39 | +//! b: u8, |
| 40 | +//! ph: PhantomData<(T, U)>, |
| 41 | +//! } |
| 42 | +//! |
| 43 | +//! let var1 = Example1 { |
| 44 | +//! a: 42, |
| 45 | +//! b: 42, |
| 46 | +//! ph: PhantomData::<((), ())>, |
| 47 | +//! }; |
| 48 | +//! let var2 = Example1 { |
| 49 | +//! a: 42, |
| 50 | +//! b: 0, |
| 51 | +//! ph: PhantomData::<((), ())>, |
| 52 | +//! }; |
| 53 | +//! |
| 54 | +//! // Field `b` is not compared, as expected. |
| 55 | +//! assert_eq!(var1, var2); |
| 56 | +//! |
| 57 | +//! #[derive_where::derive_where(Clone, Debug; T)] |
| 58 | +//! #[derive_where::derive_where(PartialEq)] |
| 59 | +//! struct Example2<T, U> { |
| 60 | +//! a: u8, |
| 61 | +//! #[derive_where(skip)] |
| 62 | +//! b: u8, |
| 63 | +//! ph: PhantomData<(T, U)>, |
| 64 | +//! } |
| 65 | +//! |
| 66 | +//! let var1 = Example2 { |
| 67 | +//! a: 42, |
| 68 | +//! b: 42, |
| 69 | +//! ph: PhantomData::<((), ())>, |
| 70 | +//! }; |
| 71 | +//! let var2 = Example2 { |
| 72 | +//! a: 42, |
| 73 | +//! b: 0, |
| 74 | +//! ph: PhantomData::<((), ())>, |
| 75 | +//! }; |
| 76 | +//! |
| 77 | +//! // Field `b` is compared! |
| 78 | +//! assert_ne!(var1, var2); |
| 79 | +//! ``` |
| 80 | +//! |
28 | 81 | //! In addition, the following convenience options are available: |
29 | 82 | //! |
30 | 83 | //! ## Generic type bounds |
|
0 commit comments