@@ -74,20 +74,6 @@ impl WeekdaySet {
74
74
}
75
75
}
76
76
77
- /// Returns `true` if `other` contains all days in `self`.
78
- ///
79
- /// # Example
80
- /// ```
81
- /// # use chrono::WeekdaySet;
82
- /// use chrono::Weekday::*;
83
- /// assert!(WeekdaySet::single(Mon).is_subset(WeekdaySet::ALL));
84
- /// assert!(!WeekdaySet::single(Mon).is_subset(WeekdaySet::EMPTY));
85
- /// assert!(WeekdaySet::EMPTY.is_subset(WeekdaySet::single(Mon)));
86
- /// ```
87
- pub const fn is_subset ( self , other : Self ) -> bool {
88
- self . intersection ( other) . 0 == self . 0
89
- }
90
-
91
77
/// Adds a day to the collection.
92
78
///
93
79
/// Returns `true` if the day was new to the collection.
@@ -130,6 +116,82 @@ impl WeekdaySet {
130
116
false
131
117
}
132
118
119
+ /// Returns `true` if `other` contains all days in `self`.
120
+ ///
121
+ /// # Example
122
+ /// ```
123
+ /// # use chrono::WeekdaySet;
124
+ /// use chrono::Weekday::*;
125
+ /// assert!(WeekdaySet::single(Mon).is_subset(WeekdaySet::ALL));
126
+ /// assert!(!WeekdaySet::single(Mon).is_subset(WeekdaySet::EMPTY));
127
+ /// assert!(WeekdaySet::EMPTY.is_subset(WeekdaySet::single(Mon)));
128
+ /// ```
129
+ pub const fn is_subset ( self , other : Self ) -> bool {
130
+ self . intersection ( other) . 0 == self . 0
131
+ }
132
+
133
+ /// Returns days that are in both `self` and `other`.
134
+ ///
135
+ /// # Example
136
+ /// ```
137
+ /// # use chrono::WeekdaySet;
138
+ /// use chrono::Weekday::*;
139
+ /// assert_eq!(WeekdaySet::single(Mon).intersection(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
140
+ /// assert_eq!(WeekdaySet::single(Mon).intersection(WeekdaySet::single(Tue)), WeekdaySet::EMPTY);
141
+ /// assert_eq!(WeekdaySet::ALL.intersection(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
142
+ /// assert_eq!(WeekdaySet::ALL.intersection(WeekdaySet::EMPTY), WeekdaySet::EMPTY);
143
+ /// ```
144
+ pub const fn intersection ( self , other : Self ) -> Self {
145
+ Self ( self . 0 & other. 0 )
146
+ }
147
+
148
+ /// Returns days that are in either `self` or `other`.
149
+ ///
150
+ /// # Example
151
+ /// ```
152
+ /// # use chrono::WeekdaySet;
153
+ /// use chrono::Weekday::*;
154
+ /// assert_eq!(WeekdaySet::single(Mon).union(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
155
+ /// assert_eq!(WeekdaySet::single(Mon).union(WeekdaySet::single(Tue)), WeekdaySet::from_array([Mon, Tue]));
156
+ /// assert_eq!(WeekdaySet::ALL.union(WeekdaySet::single(Mon)), WeekdaySet::ALL);
157
+ /// assert_eq!(WeekdaySet::ALL.union(WeekdaySet::EMPTY), WeekdaySet::ALL);
158
+ /// ```
159
+ pub const fn union ( self , other : Self ) -> Self {
160
+ Self ( self . 0 | other. 0 )
161
+ }
162
+
163
+ /// Returns days that are in `self` or `other` but not in both.
164
+ ///
165
+ /// # Example
166
+ /// ```
167
+ /// # use chrono::WeekdaySet;
168
+ /// use chrono::Weekday::*;
169
+ /// assert_eq!(WeekdaySet::single(Mon).symmetric_difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
170
+ /// assert_eq!(WeekdaySet::single(Mon).symmetric_difference(WeekdaySet::single(Tue)), WeekdaySet::from_array([Mon, Tue]));
171
+ /// assert_eq!(
172
+ /// WeekdaySet::ALL.symmetric_difference(WeekdaySet::single(Mon)),
173
+ /// WeekdaySet::from_array([Tue, Wed, Thu, Fri, Sat, Sun]),
174
+ /// );
175
+ /// assert_eq!(WeekdaySet::ALL.symmetric_difference(WeekdaySet::EMPTY), WeekdaySet::ALL);
176
+ /// ```
177
+ pub const fn symmetric_difference ( self , other : Self ) -> Self {
178
+ Self ( self . 0 ^ other. 0 )
179
+ }
180
+
181
+ /// Returns days that are in `self` but not in `other`.
182
+ ///
183
+ /// # Example
184
+ /// ```
185
+ /// # use chrono::WeekdaySet;
186
+ /// use chrono::Weekday::*;
187
+ /// assert_eq!(WeekdaySet::single(Mon).difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
188
+ /// assert_eq!(WeekdaySet::single(Mon).difference(WeekdaySet::single(Tue)), WeekdaySet::single(Mon));
189
+ /// assert_eq!(WeekdaySet::EMPTY.difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
190
+ /// ```
191
+ pub const fn difference ( self , other : Self ) -> Self {
192
+ Self ( self . 0 & !other. 0 )
193
+ }
194
+
133
195
/// Get the first day in the collection, starting from Monday.
134
196
///
135
197
/// Returns `None` if the collection is empty.
@@ -208,68 +270,6 @@ impl WeekdaySet {
208
270
WeekdaySetIter { days : self , start }
209
271
}
210
272
211
- /// Returns days that are in both `self` and `other`.
212
- ///
213
- /// # Example
214
- /// ```
215
- /// # use chrono::WeekdaySet;
216
- /// use chrono::Weekday::*;
217
- /// assert_eq!(WeekdaySet::single(Mon).intersection(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
218
- /// assert_eq!(WeekdaySet::single(Mon).intersection(WeekdaySet::single(Tue)), WeekdaySet::EMPTY);
219
- /// assert_eq!(WeekdaySet::ALL.intersection(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
220
- /// assert_eq!(WeekdaySet::ALL.intersection(WeekdaySet::EMPTY), WeekdaySet::EMPTY);
221
- /// ```
222
- pub const fn intersection ( self , other : Self ) -> Self {
223
- Self ( self . 0 & other. 0 )
224
- }
225
-
226
- /// Returns days that are in either `self` or `other`.
227
- ///
228
- /// # Example
229
- /// ```
230
- /// # use chrono::WeekdaySet;
231
- /// use chrono::Weekday::*;
232
- /// assert_eq!(WeekdaySet::single(Mon).union(WeekdaySet::single(Mon)), WeekdaySet::single(Mon));
233
- /// assert_eq!(WeekdaySet::single(Mon).union(WeekdaySet::single(Tue)), WeekdaySet::from_array([Mon, Tue]));
234
- /// assert_eq!(WeekdaySet::ALL.union(WeekdaySet::single(Mon)), WeekdaySet::ALL);
235
- /// assert_eq!(WeekdaySet::ALL.union(WeekdaySet::EMPTY), WeekdaySet::ALL);
236
- /// ```
237
- pub const fn union ( self , other : Self ) -> Self {
238
- Self ( self . 0 | other. 0 )
239
- }
240
-
241
- /// Returns days that are in `self` or `other` but not in both.
242
- ///
243
- /// # Example
244
- /// ```
245
- /// # use chrono::WeekdaySet;
246
- /// use chrono::Weekday::*;
247
- /// assert_eq!(WeekdaySet::single(Mon).symmetric_difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
248
- /// assert_eq!(WeekdaySet::single(Mon).symmetric_difference(WeekdaySet::single(Tue)), WeekdaySet::from_array([Mon, Tue]));
249
- /// assert_eq!(
250
- /// WeekdaySet::ALL.symmetric_difference(WeekdaySet::single(Mon)),
251
- /// WeekdaySet::from_array([Tue, Wed, Thu, Fri, Sat, Sun]),
252
- /// );
253
- /// assert_eq!(WeekdaySet::ALL.symmetric_difference(WeekdaySet::EMPTY), WeekdaySet::ALL);
254
- /// ```
255
- pub const fn symmetric_difference ( self , other : Self ) -> Self {
256
- Self ( self . 0 ^ other. 0 )
257
- }
258
-
259
- /// Returns days that are in `self` but not in `other`.
260
- ///
261
- /// # Example
262
- /// ```
263
- /// # use chrono::WeekdaySet;
264
- /// use chrono::Weekday::*;
265
- /// assert_eq!(WeekdaySet::single(Mon).difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
266
- /// assert_eq!(WeekdaySet::single(Mon).difference(WeekdaySet::single(Tue)), WeekdaySet::single(Mon));
267
- /// assert_eq!(WeekdaySet::EMPTY.difference(WeekdaySet::single(Mon)), WeekdaySet::EMPTY);
268
- /// ```
269
- pub const fn difference ( self , other : Self ) -> Self {
270
- Self ( self . 0 & !other. 0 )
271
- }
272
-
273
273
/// Returns `true` if the collection contains the given day.
274
274
///
275
275
/// # Example
0 commit comments