Skip to content

Commit 9d5c41a

Browse files
author
lukas
committed
Add #[must_use] to some methods
1 parent 4e2c2b4 commit 9d5c41a

19 files changed

+208
-2
lines changed

src/date.rs

+27
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl<Tz: TimeZone> Date<Tz> {
7777
//
7878
// note: this constructor is purposely not named to `new` to discourage the direct usage.
7979
#[inline]
80+
#[must_use]
8081
pub fn from_utc(date: NaiveDate, offset: Tz::Offset) -> Date<Tz> {
8182
Date { date, offset }
8283
}
@@ -86,6 +87,7 @@ impl<Tz: TimeZone> Date<Tz> {
8687
///
8788
/// Panics on invalid datetime.
8889
#[inline]
90+
#[must_use]
8991
pub fn and_time(&self, time: NaiveTime) -> Option<DateTime<Tz>> {
9092
let localdt = self.naive_local().and_time(time);
9193
self.timezone().from_local_datetime(&localdt).single()
@@ -97,6 +99,7 @@ impl<Tz: TimeZone> Date<Tz> {
9799
/// Panics on invalid hour, minute and/or second.
98100
#[deprecated(since = "0.4.23", note = "Use and_hms_opt() instead")]
99101
#[inline]
102+
#[must_use]
100103
pub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> DateTime<Tz> {
101104
self.and_hms_opt(hour, min, sec).expect("invalid time")
102105
}
@@ -106,6 +109,7 @@ impl<Tz: TimeZone> Date<Tz> {
106109
///
107110
/// Returns `None` on invalid hour, minute and/or second.
108111
#[inline]
112+
#[must_use]
109113
pub fn and_hms_opt(&self, hour: u32, min: u32, sec: u32) -> Option<DateTime<Tz>> {
110114
NaiveTime::from_hms_opt(hour, min, sec).and_then(|time| self.and_time(time))
111115
}
@@ -117,6 +121,7 @@ impl<Tz: TimeZone> Date<Tz> {
117121
/// Panics on invalid hour, minute, second and/or millisecond.
118122
#[deprecated(since = "0.4.23", note = "Use and_hms_milli_opt() instead")]
119123
#[inline]
124+
#[must_use]
120125
pub fn and_hms_milli(&self, hour: u32, min: u32, sec: u32, milli: u32) -> DateTime<Tz> {
121126
self.and_hms_milli_opt(hour, min, sec, milli).expect("invalid time")
122127
}
@@ -127,6 +132,7 @@ impl<Tz: TimeZone> Date<Tz> {
127132
///
128133
/// Returns `None` on invalid hour, minute, second and/or millisecond.
129134
#[inline]
135+
#[must_use]
130136
pub fn and_hms_milli_opt(
131137
&self,
132138
hour: u32,
@@ -144,6 +150,7 @@ impl<Tz: TimeZone> Date<Tz> {
144150
/// Panics on invalid hour, minute, second and/or microsecond.
145151
#[deprecated(since = "0.4.23", note = "Use and_hms_micro_opt() instead")]
146152
#[inline]
153+
#[must_use]
147154
pub fn and_hms_micro(&self, hour: u32, min: u32, sec: u32, micro: u32) -> DateTime<Tz> {
148155
self.and_hms_micro_opt(hour, min, sec, micro).expect("invalid time")
149156
}
@@ -154,6 +161,7 @@ impl<Tz: TimeZone> Date<Tz> {
154161
///
155162
/// Returns `None` on invalid hour, minute, second and/or microsecond.
156163
#[inline]
164+
#[must_use]
157165
pub fn and_hms_micro_opt(
158166
&self,
159167
hour: u32,
@@ -171,6 +179,7 @@ impl<Tz: TimeZone> Date<Tz> {
171179
/// Panics on invalid hour, minute, second and/or nanosecond.
172180
#[deprecated(since = "0.4.23", note = "Use and_hms_nano_opt() instead")]
173181
#[inline]
182+
#[must_use]
174183
pub fn and_hms_nano(&self, hour: u32, min: u32, sec: u32, nano: u32) -> DateTime<Tz> {
175184
self.and_hms_nano_opt(hour, min, sec, nano).expect("invalid time")
176185
}
@@ -181,6 +190,7 @@ impl<Tz: TimeZone> Date<Tz> {
181190
///
182191
/// Returns `None` on invalid hour, minute, second and/or nanosecond.
183192
#[inline]
193+
#[must_use]
184194
pub fn and_hms_nano_opt(
185195
&self,
186196
hour: u32,
@@ -196,6 +206,7 @@ impl<Tz: TimeZone> Date<Tz> {
196206
/// Panics when `self` is the last representable date.
197207
#[deprecated(since = "0.4.23", note = "Use succ_opt() instead")]
198208
#[inline]
209+
#[must_use]
199210
pub fn succ(&self) -> Date<Tz> {
200211
self.succ_opt().expect("out of bound")
201212
}
@@ -204,6 +215,7 @@ impl<Tz: TimeZone> Date<Tz> {
204215
///
205216
/// Returns `None` when `self` is the last representable date.
206217
#[inline]
218+
#[must_use]
207219
pub fn succ_opt(&self) -> Option<Date<Tz>> {
208220
self.date.succ_opt().map(|date| Date::from_utc(date, self.offset.clone()))
209221
}
@@ -213,6 +225,7 @@ impl<Tz: TimeZone> Date<Tz> {
213225
/// Panics when `self` is the first representable date.
214226
#[deprecated(since = "0.4.23", note = "Use pred_opt() instead")]
215227
#[inline]
228+
#[must_use]
216229
pub fn pred(&self) -> Date<Tz> {
217230
self.pred_opt().expect("out of bound")
218231
}
@@ -221,25 +234,29 @@ impl<Tz: TimeZone> Date<Tz> {
221234
///
222235
/// Returns `None` when `self` is the first representable date.
223236
#[inline]
237+
#[must_use]
224238
pub fn pred_opt(&self) -> Option<Date<Tz>> {
225239
self.date.pred_opt().map(|date| Date::from_utc(date, self.offset.clone()))
226240
}
227241

228242
/// Retrieves an associated offset from UTC.
229243
#[inline]
244+
#[must_use]
230245
pub fn offset(&self) -> &Tz::Offset {
231246
&self.offset
232247
}
233248

234249
/// Retrieves an associated time zone.
235250
#[inline]
251+
#[must_use]
236252
pub fn timezone(&self) -> Tz {
237253
TimeZone::from_offset(&self.offset)
238254
}
239255

240256
/// Changes the associated time zone.
241257
/// This does not change the actual `Date` (but will change the string representation).
242258
#[inline]
259+
#[must_use]
243260
pub fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> Date<Tz2> {
244261
tz.from_utc_date(&self.date)
245262
}
@@ -248,6 +265,7 @@ impl<Tz: TimeZone> Date<Tz> {
248265
///
249266
/// Returns `None` when it will result in overflow.
250267
#[inline]
268+
#[must_use]
251269
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
252270
let date = self.date.checked_add_signed(rhs)?;
253271
Some(Date { date, offset: self.offset })
@@ -257,6 +275,7 @@ impl<Tz: TimeZone> Date<Tz> {
257275
///
258276
/// Returns `None` when it will result in overflow.
259277
#[inline]
278+
#[must_use]
260279
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
261280
let date = self.date.checked_sub_signed(rhs)?;
262281
Some(Date { date, offset: self.offset })
@@ -268,12 +287,14 @@ impl<Tz: TimeZone> Date<Tz> {
268287
/// This does not overflow or underflow at all,
269288
/// as all possible output fits in the range of `Duration`.
270289
#[inline]
290+
#[must_use]
271291
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> OldDuration {
272292
self.date.signed_duration_since(rhs.date)
273293
}
274294

275295
/// Returns a view to the naive UTC date.
276296
#[inline]
297+
#[must_use]
277298
pub fn naive_utc(&self) -> NaiveDate {
278299
self.date
279300
}
@@ -284,11 +305,13 @@ impl<Tz: TimeZone> Date<Tz> {
284305
/// because the offset is restricted to never exceed one day,
285306
/// but provided for the consistency.
286307
#[inline]
308+
#[must_use]
287309
pub fn naive_local(&self) -> NaiveDate {
288310
self.date
289311
}
290312

291313
/// Returns the number of whole years from the given `base` until `self`.
314+
#[must_use]
292315
pub fn years_since(&self, base: Self) -> Option<u32> {
293316
self.date.years_since(base.date)
294317
}
@@ -315,6 +338,7 @@ where
315338
#[cfg(any(feature = "alloc", feature = "std", test))]
316339
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
317340
#[inline]
341+
#[must_use]
318342
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
319343
where
320344
I: Iterator<Item = B> + Clone,
@@ -329,6 +353,7 @@ where
329353
#[cfg(any(feature = "alloc", feature = "std", test))]
330354
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
331355
#[inline]
356+
#[must_use]
332357
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> {
333358
self.format_with_items(StrftimeItems::new(fmt))
334359
}
@@ -337,6 +362,7 @@ where
337362
#[cfg(feature = "unstable-locales")]
338363
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
339364
#[inline]
365+
#[must_use]
340366
pub fn format_localized_with_items<'a, I, B>(
341367
&self,
342368
items: I,
@@ -361,6 +387,7 @@ where
361387
#[cfg(feature = "unstable-locales")]
362388
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
363389
#[inline]
390+
#[must_use]
364391
pub fn format_localized<'a>(
365392
&self,
366393
fmt: &'a str,

0 commit comments

Comments
 (0)