|
30 | 30 | //!
|
31 | 31 | //! ```
|
32 | 32 | //! # use std::marker::PhantomData;
|
33 |
| -//! #[derive_where::derive_where(Clone)] |
34 |
| -//! #[derive_where(Debug)] |
| 33 | +//! #[derive_where::derive_where(Clone, Debug)] |
| 34 | +//! #[derive_where(Eq, PartialEq)] |
35 | 35 | //! struct Example1<T>(PhantomData<T>);
|
36 | 36 | //! ```
|
37 | 37 | //!
|
|
57 | 57 | //! ```
|
58 | 58 | //! # use std::marker::PhantomData;
|
59 | 59 | //! # use derive_where::derive_where;
|
60 |
| -//! #[derive_where(Clone; T)] |
| 60 | +//! #[derive_where(Clone, Debug; T)] |
61 | 61 | //! struct Example<T, U>(T, PhantomData<U>);
|
62 | 62 | //! ```
|
63 | 63 | //!
|
64 | 64 | //! It is also possible to specify the bounds to be applied. This will
|
65 | 65 | //! bind implementation for `Example` to `T: Super`:
|
66 | 66 | //!
|
67 | 67 | //! ```
|
| 68 | +//! # use std::fmt::Debug; |
68 | 69 | //! # use std::marker::PhantomData;
|
69 | 70 | //! # use derive_where::derive_where;
|
70 |
| -//! trait Super: Clone {} |
| 71 | +//! trait Super: Clone + Debug {} |
71 | 72 | //!
|
72 |
| -//! #[derive_where(Clone; T: Super)] |
| 73 | +//! #[derive_where(Clone, Debug; T: Super)] |
73 | 74 | //! struct Example<T>(PhantomData<T>);
|
74 | 75 | //! ```
|
75 | 76 | //!
|
76 | 77 | //! But more complex trait bounds are possible as well.
|
77 |
| -//! The example below will restrict the implementation for `Example` to |
78 |
| -//! `T::Type: Clone`: |
| 78 | +//! The example below will restrict the [`Clone`] implementation for `Example` |
| 79 | +//! to `T::Type: Clone`: |
79 | 80 | //!
|
80 | 81 | //! ```
|
81 | 82 | //! # use std::marker::PhantomData;
|
|
90 | 91 | //! type Type = i32;
|
91 | 92 | //! }
|
92 | 93 | //!
|
93 |
| -//! #[derive_where(Clone; T::Type)] |
| 94 | +//! #[derive_where(Clone, Debug; T::Type)] |
94 | 95 | //! struct Example<T: Trait>(T::Type);
|
95 | 96 | //! ```
|
96 | 97 | //!
|
|
101 | 102 | //! ```
|
102 | 103 | //! # use std::marker::PhantomData;
|
103 | 104 | //! # use derive_where::derive_where;
|
104 |
| -//! #[derive_where(Clone; T)] |
105 |
| -//! #[derive_where(Debug; U)] |
| 105 | +//! #[derive_where(Clone, Debug; T)] |
| 106 | +//! #[derive_where(Eq, PartialEq; U)] |
106 | 107 | //! struct Example<T, U>(PhantomData<T>, PhantomData<U>);
|
107 | 108 | //! ```
|
108 | 109 | //!
|
|
115 | 116 | //! ```
|
116 | 117 | //! # use std::marker::PhantomData;
|
117 | 118 | //! # use derive_where::derive_where;
|
118 |
| -//! #[derive_where(Default)] |
| 119 | +//! #[derive_where(Clone, Default)] |
119 | 120 | //! enum Example<T> {
|
120 | 121 | //! #[derive_where(default)]
|
121 | 122 | //! A(PhantomData<T>),
|
|
143 | 144 | //! ```
|
144 | 145 | //! # use std::marker::PhantomData;
|
145 | 146 | //! # use derive_where::derive_where;
|
146 |
| -//! #[derive_where(Debug)] |
| 147 | +//! #[derive_where(Debug, PartialEq)] |
147 | 148 | //! #[derive_where(skip_inner)]
|
148 | 149 | //! struct StructExample<T>(T);
|
149 | 150 | //!
|
150 | 151 | //! assert_eq!(format!("{:?}", StructExample(42)), "StructExample");
|
| 152 | +//! assert_eq!(StructExample(42), StructExample(0)); |
151 | 153 | //!
|
152 |
| -//! #[derive_where(Debug)] |
| 154 | +//! #[derive_where(Debug, PartialEq)] |
153 | 155 | //! enum EnumExample<T> {
|
154 | 156 | //! #[derive_where(skip_inner)]
|
155 | 157 | //! A(T),
|
156 | 158 | //! }
|
157 | 159 | //!
|
158 | 160 | //! assert_eq!(format!("{:?}", EnumExample::A(42)), "A");
|
| 161 | +//! assert_eq!(EnumExample::A(42), EnumExample::A(0)); |
159 | 162 | //! ```
|
160 | 163 | //!
|
161 | 164 | //! Selective skipping of fields for certain traits is also an option, both in
|
|
0 commit comments