@@ -77,6 +77,7 @@ impl<Tz: TimeZone> Date<Tz> {
77
77
//
78
78
// note: this constructor is purposely not named to `new` to discourage the direct usage.
79
79
#[ inline]
80
+ #[ must_use]
80
81
pub fn from_utc ( date : NaiveDate , offset : Tz :: Offset ) -> Date < Tz > {
81
82
Date { date, offset }
82
83
}
@@ -86,6 +87,7 @@ impl<Tz: TimeZone> Date<Tz> {
86
87
///
87
88
/// Panics on invalid datetime.
88
89
#[ inline]
90
+ #[ must_use]
89
91
pub fn and_time ( & self , time : NaiveTime ) -> Option < DateTime < Tz > > {
90
92
let localdt = self . naive_local ( ) . and_time ( time) ;
91
93
self . timezone ( ) . from_local_datetime ( & localdt) . single ( )
@@ -97,6 +99,7 @@ impl<Tz: TimeZone> Date<Tz> {
97
99
/// Panics on invalid hour, minute and/or second.
98
100
#[ deprecated( since = "0.4.23" , note = "Use and_hms_opt() instead" ) ]
99
101
#[ inline]
102
+ #[ must_use]
100
103
pub fn and_hms ( & self , hour : u32 , min : u32 , sec : u32 ) -> DateTime < Tz > {
101
104
self . and_hms_opt ( hour, min, sec) . expect ( "invalid time" )
102
105
}
@@ -106,6 +109,7 @@ impl<Tz: TimeZone> Date<Tz> {
106
109
///
107
110
/// Returns `None` on invalid hour, minute and/or second.
108
111
#[ inline]
112
+ #[ must_use]
109
113
pub fn and_hms_opt ( & self , hour : u32 , min : u32 , sec : u32 ) -> Option < DateTime < Tz > > {
110
114
NaiveTime :: from_hms_opt ( hour, min, sec) . and_then ( |time| self . and_time ( time) )
111
115
}
@@ -117,6 +121,7 @@ impl<Tz: TimeZone> Date<Tz> {
117
121
/// Panics on invalid hour, minute, second and/or millisecond.
118
122
#[ deprecated( since = "0.4.23" , note = "Use and_hms_milli_opt() instead" ) ]
119
123
#[ inline]
124
+ #[ must_use]
120
125
pub fn and_hms_milli ( & self , hour : u32 , min : u32 , sec : u32 , milli : u32 ) -> DateTime < Tz > {
121
126
self . and_hms_milli_opt ( hour, min, sec, milli) . expect ( "invalid time" )
122
127
}
@@ -127,6 +132,7 @@ impl<Tz: TimeZone> Date<Tz> {
127
132
///
128
133
/// Returns `None` on invalid hour, minute, second and/or millisecond.
129
134
#[ inline]
135
+ #[ must_use]
130
136
pub fn and_hms_milli_opt (
131
137
& self ,
132
138
hour : u32 ,
@@ -144,6 +150,7 @@ impl<Tz: TimeZone> Date<Tz> {
144
150
/// Panics on invalid hour, minute, second and/or microsecond.
145
151
#[ deprecated( since = "0.4.23" , note = "Use and_hms_micro_opt() instead" ) ]
146
152
#[ inline]
153
+ #[ must_use]
147
154
pub fn and_hms_micro ( & self , hour : u32 , min : u32 , sec : u32 , micro : u32 ) -> DateTime < Tz > {
148
155
self . and_hms_micro_opt ( hour, min, sec, micro) . expect ( "invalid time" )
149
156
}
@@ -154,6 +161,7 @@ impl<Tz: TimeZone> Date<Tz> {
154
161
///
155
162
/// Returns `None` on invalid hour, minute, second and/or microsecond.
156
163
#[ inline]
164
+ #[ must_use]
157
165
pub fn and_hms_micro_opt (
158
166
& self ,
159
167
hour : u32 ,
@@ -171,6 +179,7 @@ impl<Tz: TimeZone> Date<Tz> {
171
179
/// Panics on invalid hour, minute, second and/or nanosecond.
172
180
#[ deprecated( since = "0.4.23" , note = "Use and_hms_nano_opt() instead" ) ]
173
181
#[ inline]
182
+ #[ must_use]
174
183
pub fn and_hms_nano ( & self , hour : u32 , min : u32 , sec : u32 , nano : u32 ) -> DateTime < Tz > {
175
184
self . and_hms_nano_opt ( hour, min, sec, nano) . expect ( "invalid time" )
176
185
}
@@ -181,6 +190,7 @@ impl<Tz: TimeZone> Date<Tz> {
181
190
///
182
191
/// Returns `None` on invalid hour, minute, second and/or nanosecond.
183
192
#[ inline]
193
+ #[ must_use]
184
194
pub fn and_hms_nano_opt (
185
195
& self ,
186
196
hour : u32 ,
@@ -196,6 +206,7 @@ impl<Tz: TimeZone> Date<Tz> {
196
206
/// Panics when `self` is the last representable date.
197
207
#[ deprecated( since = "0.4.23" , note = "Use succ_opt() instead" ) ]
198
208
#[ inline]
209
+ #[ must_use]
199
210
pub fn succ ( & self ) -> Date < Tz > {
200
211
self . succ_opt ( ) . expect ( "out of bound" )
201
212
}
@@ -204,6 +215,7 @@ impl<Tz: TimeZone> Date<Tz> {
204
215
///
205
216
/// Returns `None` when `self` is the last representable date.
206
217
#[ inline]
218
+ #[ must_use]
207
219
pub fn succ_opt ( & self ) -> Option < Date < Tz > > {
208
220
self . date . succ_opt ( ) . map ( |date| Date :: from_utc ( date, self . offset . clone ( ) ) )
209
221
}
@@ -213,6 +225,7 @@ impl<Tz: TimeZone> Date<Tz> {
213
225
/// Panics when `self` is the first representable date.
214
226
#[ deprecated( since = "0.4.23" , note = "Use pred_opt() instead" ) ]
215
227
#[ inline]
228
+ #[ must_use]
216
229
pub fn pred ( & self ) -> Date < Tz > {
217
230
self . pred_opt ( ) . expect ( "out of bound" )
218
231
}
@@ -221,25 +234,29 @@ impl<Tz: TimeZone> Date<Tz> {
221
234
///
222
235
/// Returns `None` when `self` is the first representable date.
223
236
#[ inline]
237
+ #[ must_use]
224
238
pub fn pred_opt ( & self ) -> Option < Date < Tz > > {
225
239
self . date . pred_opt ( ) . map ( |date| Date :: from_utc ( date, self . offset . clone ( ) ) )
226
240
}
227
241
228
242
/// Retrieves an associated offset from UTC.
229
243
#[ inline]
244
+ #[ must_use]
230
245
pub fn offset ( & self ) -> & Tz :: Offset {
231
246
& self . offset
232
247
}
233
248
234
249
/// Retrieves an associated time zone.
235
250
#[ inline]
251
+ #[ must_use]
236
252
pub fn timezone ( & self ) -> Tz {
237
253
TimeZone :: from_offset ( & self . offset )
238
254
}
239
255
240
256
/// Changes the associated time zone.
241
257
/// This does not change the actual `Date` (but will change the string representation).
242
258
#[ inline]
259
+ #[ must_use]
243
260
pub fn with_timezone < Tz2 : TimeZone > ( & self , tz : & Tz2 ) -> Date < Tz2 > {
244
261
tz. from_utc_date ( & self . date )
245
262
}
@@ -248,6 +265,7 @@ impl<Tz: TimeZone> Date<Tz> {
248
265
///
249
266
/// Returns `None` when it will result in overflow.
250
267
#[ inline]
268
+ #[ must_use]
251
269
pub fn checked_add_signed ( self , rhs : OldDuration ) -> Option < Date < Tz > > {
252
270
let date = self . date . checked_add_signed ( rhs) ?;
253
271
Some ( Date { date, offset : self . offset } )
@@ -257,6 +275,7 @@ impl<Tz: TimeZone> Date<Tz> {
257
275
///
258
276
/// Returns `None` when it will result in overflow.
259
277
#[ inline]
278
+ #[ must_use]
260
279
pub fn checked_sub_signed ( self , rhs : OldDuration ) -> Option < Date < Tz > > {
261
280
let date = self . date . checked_sub_signed ( rhs) ?;
262
281
Some ( Date { date, offset : self . offset } )
@@ -268,12 +287,14 @@ impl<Tz: TimeZone> Date<Tz> {
268
287
/// This does not overflow or underflow at all,
269
288
/// as all possible output fits in the range of `Duration`.
270
289
#[ inline]
290
+ #[ must_use]
271
291
pub fn signed_duration_since < Tz2 : TimeZone > ( self , rhs : Date < Tz2 > ) -> OldDuration {
272
292
self . date . signed_duration_since ( rhs. date )
273
293
}
274
294
275
295
/// Returns a view to the naive UTC date.
276
296
#[ inline]
297
+ #[ must_use]
277
298
pub fn naive_utc ( & self ) -> NaiveDate {
278
299
self . date
279
300
}
@@ -284,11 +305,13 @@ impl<Tz: TimeZone> Date<Tz> {
284
305
/// because the offset is restricted to never exceed one day,
285
306
/// but provided for the consistency.
286
307
#[ inline]
308
+ #[ must_use]
287
309
pub fn naive_local ( & self ) -> NaiveDate {
288
310
self . date
289
311
}
290
312
291
313
/// Returns the number of whole years from the given `base` until `self`.
314
+ #[ must_use]
292
315
pub fn years_since ( & self , base : Self ) -> Option < u32 > {
293
316
self . date . years_since ( base. date )
294
317
}
@@ -315,6 +338,7 @@ where
315
338
#[ cfg( any( feature = "alloc" , feature = "std" , test) ) ]
316
339
#[ cfg_attr( docsrs, doc( cfg( any( feature = "alloc" , feature = "std" ) ) ) ) ]
317
340
#[ inline]
341
+ #[ must_use]
318
342
pub fn format_with_items < ' a , I , B > ( & self , items : I ) -> DelayedFormat < I >
319
343
where
320
344
I : Iterator < Item = B > + Clone ,
@@ -329,6 +353,7 @@ where
329
353
#[ cfg( any( feature = "alloc" , feature = "std" , test) ) ]
330
354
#[ cfg_attr( docsrs, doc( cfg( any( feature = "alloc" , feature = "std" ) ) ) ) ]
331
355
#[ inline]
356
+ #[ must_use]
332
357
pub fn format < ' a > ( & self , fmt : & ' a str ) -> DelayedFormat < StrftimeItems < ' a > > {
333
358
self . format_with_items ( StrftimeItems :: new ( fmt) )
334
359
}
@@ -337,6 +362,7 @@ where
337
362
#[ cfg( feature = "unstable-locales" ) ]
338
363
#[ cfg_attr( docsrs, doc( cfg( feature = "unstable-locales" ) ) ) ]
339
364
#[ inline]
365
+ #[ must_use]
340
366
pub fn format_localized_with_items < ' a , I , B > (
341
367
& self ,
342
368
items : I ,
@@ -361,6 +387,7 @@ where
361
387
#[ cfg( feature = "unstable-locales" ) ]
362
388
#[ cfg_attr( docsrs, doc( cfg( feature = "unstable-locales" ) ) ) ]
363
389
#[ inline]
390
+ #[ must_use]
364
391
pub fn format_localized < ' a > (
365
392
& self ,
366
393
fmt : & ' a str ,
0 commit comments