Skip to main content

time/format_description/
modifier.rs

1//! Various modifiers for components.
2
3use core::num::NonZero;
4
5/// Generate the provided code if and only if `pub` is present.
6macro_rules! if_pub {
7    (pub $(#[$attr:meta])*; $($x:tt)*) => {
8        $(#[$attr])*
9        ///
10        /// This function exists since [`Default::default()`] cannot be used in a `const` context.
11        /// It may be removed once that becomes possible. As the [`Default`] trait is in the
12        /// prelude, removing this function in the future will not cause any resolution failures for
13        /// the overwhelming majority of users; only users who use `#![no_implicit_prelude]` will be
14        /// affected. As such it will not be considered a breaking change.
15        $($x)*
16    };
17    ($($_:tt)*) => {};
18}
19
20/// Implement `Default` for the given type. This also generates an inherent implementation of a
21/// `default` method that is `const fn`, permitting the default value to be used in const contexts.
22// Every modifier should use this macro rather than a derived `Default`.
23macro_rules! impl_const_default {
24    ($($(
25        #[doc = $doc:expr])*
26        $(#[cfg($($cfg:tt)+)])?
27        $(#[expect($($expected:tt)+)])?
28        $(@$pub:ident)? $type:ty => $default:expr;
29    )*) => {$(
30        $(#[cfg($($cfg)+)])?
31        $(#[expect($($expected)+)])?
32        impl $type {
33            if_pub! {
34                $($pub)?
35                $(#[doc = $doc])*;
36                #[inline]
37                pub const fn default() -> Self {
38                    $default
39                }
40            }
41        }
42
43        $(#[doc = $doc])*
44        $(#[cfg($($cfg)+)])?
45        $(#[expect($($expected)+)])?
46        impl Default for $type {
47            #[inline]
48            fn default() -> Self {
49                $default
50            }
51        }
52    )*};
53}
54
55// Keep this first so that it's shown at the top of documentation.
56impl_const_default! {
57    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
58    @pub Day => Self { padding: Padding::Zero };
59    /// Creates a modifier that indicates the value uses the
60    /// [`Numerical`](Self::Numerical) representation.
61    #[expect(deprecated)]
62    MonthRepr => Self::Numerical;
63    @pub MonthShort => Self { case_sensitive: true };
64    @pub MonthLong => Self { case_sensitive: true };
65    @pub MonthNumerical => Self { padding: Padding::Zero };
66    /// Creates an instance of this type that indicates the value uses the
67    /// [`Numerical`](MonthRepr::Numerical) representation, is [padded with zeroes](Padding::Zero),
68    /// and is case-sensitive when parsing.
69    #[expect(deprecated)]
70    @pub Month => Self {
71        padding: Padding::Zero,
72        repr: MonthRepr::Numerical,
73        case_sensitive: true,
74    };
75    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
76    @pub Ordinal => Self { padding: Padding::Zero };
77    /// Creates a modifier that indicates the value uses the [`Long`](Self::Long) representation.
78    #[expect(deprecated)]
79    WeekdayRepr => Self::Long;
80    @pub WeekdayShort => Self { case_sensitive: true };
81    @pub WeekdayLong => Self { case_sensitive: true };
82    @pub WeekdaySunday => Self { one_indexed: true };
83    @pub WeekdayMonday => Self { one_indexed: true };
84    /// Creates a modifier that indicates the value uses the [`Long`](WeekdayRepr::Long)
85    /// representation and is case-sensitive when parsing. If the representation is changed to a
86    /// numerical one, the instance defaults to one-based indexing.
87    #[expect(deprecated)]
88    @pub Weekday => Self {
89        repr: WeekdayRepr::Long,
90        one_indexed: true,
91        case_sensitive: true,
92    };
93    /// Creates a modifier that indicates that the value uses the [`Iso`](Self::Iso) representation.
94    #[expect(deprecated)]
95    WeekNumberRepr => Self::Iso;
96    @pub WeekNumberIso => Self { padding: Padding::Zero };
97    @pub WeekNumberSunday => Self { padding: Padding::Zero };
98    @pub WeekNumberMonday => Self { padding: Padding::Zero };
99    /// Creates a modifier that indicates that the value is [padded with zeroes](Padding::Zero)
100    /// and uses the [`Iso`](WeekNumberRepr::Iso) representation.
101    #[expect(deprecated)]
102    @pub WeekNumber => Self {
103        padding: Padding::Zero,
104        repr: WeekNumberRepr::Iso,
105    };
106    /// Creates a modifier that indicates the value uses the [`Full`](Self::Full) representation.
107    #[expect(deprecated)]
108    YearRepr => Self::Full;
109    /// Creates a modifier that indicates the value uses the [`Extended`](Self::Extended) range.
110    #[expect(deprecated)]
111    YearRange => Self::Extended;
112    @pub CalendarYearFullExtendedRange => Self {
113        padding: Padding::Zero,
114        sign_is_mandatory: false,
115    };
116    @pub CalendarYearFullStandardRange => Self {
117        padding: Padding::Zero,
118        sign_is_mandatory: false,
119    };
120    @pub IsoYearFullExtendedRange => Self {
121        padding: Padding::Zero,
122        sign_is_mandatory: false,
123    };
124    @pub IsoYearFullStandardRange => Self {
125        padding: Padding::Zero,
126        sign_is_mandatory: false,
127    };
128    @pub CalendarYearCenturyExtendedRange => Self {
129        padding: Padding::Zero,
130        sign_is_mandatory: false,
131    };
132    @pub CalendarYearCenturyStandardRange => Self {
133        padding: Padding::Zero,
134        sign_is_mandatory: false,
135    };
136    @pub IsoYearCenturyExtendedRange => Self {
137        padding: Padding::Zero,
138        sign_is_mandatory: false,
139    };
140    @pub IsoYearCenturyStandardRange => Self {
141        padding: Padding::Zero,
142        sign_is_mandatory: false,
143    };
144    @pub CalendarYearLastTwo => Self {
145        padding: Padding::Zero,
146    };
147    @pub IsoYearLastTwo => Self {
148        padding: Padding::Zero,
149    };
150    /// Creates a modifier that indicates the value uses the [`Full`](YearRepr::Full)
151    /// representation, is [padded with zeroes](Padding::Zero), uses the Gregorian calendar as its
152    /// base, and only includes the year's sign if necessary.
153    #[expect(deprecated)]
154    @pub Year => Self {
155        padding: Padding::Zero,
156        repr: YearRepr::Full,
157        range: YearRange::Extended,
158        iso_week_based: false,
159        sign_is_mandatory: false,
160    };
161    @pub Hour12 => Self { padding: Padding::Zero };
162    @pub Hour24 => Self { padding: Padding::Zero };
163    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero) and
164    /// has the 24-hour representation.
165    #[expect(deprecated)]
166    @pub Hour => Self {
167        padding: Padding::Zero,
168        is_12_hour_clock: false,
169    };
170    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
171    @pub Minute => Self { padding: Padding::Zero };
172    /// Creates a modifier that indicates the value uses the upper-case representation and is
173    /// case-sensitive when parsing.
174    @pub Period => Self {
175        is_uppercase: true,
176        case_sensitive: true,
177    };
178    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
179    @pub Second => Self { padding: Padding::Zero };
180    /// Creates a modifier that indicates the stringified value contains [one or more
181    /// digits](Self::OneOrMore).
182    SubsecondDigits => Self::OneOrMore;
183    /// Creates a modifier that indicates the stringified value contains [one or more
184    /// digits](SubsecondDigits::OneOrMore).
185    @pub Subsecond => Self { digits: SubsecondDigits::OneOrMore };
186    /// Creates a modifier that indicates the value only uses a sign for negative values and is
187    /// [padded with zeroes](Padding::Zero).
188    @pub OffsetHour => Self {
189        sign_is_mandatory: false,
190        padding: Padding::Zero,
191    };
192    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
193    @pub OffsetMinute => Self { padding: Padding::Zero };
194    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
195    @pub OffsetSecond => Self { padding: Padding::Zero };
196    /// Creates a modifier that indicates the value is [padded with zeroes](Self::Zero).
197    Padding => Self::Zero;
198    /// Creates a modifier that indicates the value represents the [number of seconds](Self::Second)
199    /// since the Unix epoch.
200    #[expect(deprecated)]
201    UnixTimestampPrecision => Self::Second;
202    @pub UnixTimestampSecond => Self { sign_is_mandatory: false };
203    @pub UnixTimestampMillisecond => Self { sign_is_mandatory: false };
204    @pub UnixTimestampMicrosecond => Self { sign_is_mandatory: false };
205    @pub UnixTimestampNanosecond => Self { sign_is_mandatory: false };
206    /// Creates a modifier that indicates the value represents the [number of
207    /// seconds](UnixTimestampPrecision::Second) since the Unix epoch. The sign is not mandatory.
208    #[expect(deprecated)]
209    @pub UnixTimestamp => Self {
210        precision: UnixTimestampPrecision::Second,
211        sign_is_mandatory: false,
212    };
213    /// Indicate that any trailing characters after the end of input are prohibited and will cause
214    /// an error when used with `parse`.
215    TrailingInput => Self::Prohibit;
216    /// Creates a modifier used to represent the end of input, not allowing any trailing input (i.e.
217    /// the input must be fully consumed).
218    @pub End => Self { trailing_input: TrailingInput::Prohibit };
219}
220
221/// Day of the month.
222#[non_exhaustive]
223#[derive(Debug, Clone, Copy, PartialEq, Eq)]
224pub struct Day {
225    /// The padding to obtain the minimum width.
226    pub padding: Padding,
227}
228
229impl Day {
230    /// Set the padding type.
231    #[inline]
232    #[must_use = "this returns the result of the operation, without modifying the original"]
233    pub const fn with_padding(self, padding: Padding) -> Self {
234        Self { padding }
235    }
236}
237
238/// The representation of a month.
239#[non_exhaustive]
240#[deprecated(
241    since = "0.3.48",
242    note = "used only in the deprecated `Month` component"
243)]
244#[derive(Debug, Clone, Copy, PartialEq, Eq)]
245pub enum MonthRepr {
246    /// The number of the month (January is 1, December is 12).
247    Numerical,
248    /// The long form of the month name (e.g. "January").
249    Long,
250    /// The short form of the month name (e.g. "Jan").
251    Short,
252}
253
254/// Month of the year using the short form of the month name (e.g. "Jan").
255#[derive(Debug, Clone, Copy, PartialEq, Eq)]
256pub struct MonthShort {
257    /// Is the value case sensitive when parsing?
258    pub(crate) case_sensitive: bool,
259}
260
261impl MonthShort {
262    /// Set whether the value is case sensitive when parsing.
263    #[inline]
264    #[must_use = "this returns the result of the operation, without modifying the original"]
265    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
266        Self { case_sensitive }
267    }
268}
269
270/// Month of the year using the long form of the month name (e.g. "January").
271#[derive(Debug, Clone, Copy, PartialEq, Eq)]
272pub struct MonthLong {
273    /// Is the value case sensitive when parsing?
274    pub(crate) case_sensitive: bool,
275}
276
277impl MonthLong {
278    /// Set whether the value is case sensitive when parsing.
279    #[inline]
280    #[must_use = "this returns the result of the operation, without modifying the original"]
281    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
282        Self { case_sensitive }
283    }
284}
285
286/// Month of the year using a numerical representation (e.g. "1" for January).
287#[derive(Debug, Clone, Copy, PartialEq, Eq)]
288pub struct MonthNumerical {
289    /// The padding to obtain the minimum width.
290    pub(crate) padding: Padding,
291}
292
293impl MonthNumerical {
294    /// Set the padding type.
295    #[inline]
296    #[must_use = "this returns the result of the operation, without modifying the original"]
297    pub const fn with_padding(self, padding: Padding) -> Self {
298        Self { padding }
299    }
300}
301
302/// Month of the year.
303#[non_exhaustive]
304#[allow(deprecated)]
305#[deprecated(
306    since = "0.3.48",
307    note = "use `MonthShort`, `MonthLong`, or `MonthNumeric` instead"
308)]
309#[derive(Debug, Clone, Copy, PartialEq, Eq)]
310pub struct Month {
311    /// The padding to obtain the minimum width.
312    pub padding: Padding,
313    /// What form of representation should be used?
314    pub repr: MonthRepr,
315    /// Is the value case sensitive when parsing?
316    pub case_sensitive: bool,
317}
318
319#[expect(deprecated)]
320impl Month {
321    /// Set the padding type.
322    #[inline]
323    #[must_use = "this returns the result of the operation, without modifying the original"]
324    pub const fn with_padding(self, padding: Padding) -> Self {
325        Self { padding, ..self }
326    }
327
328    /// Set the manner in which the month is represented.
329    #[inline]
330    #[must_use = "this returns the result of the operation, without modifying the original"]
331    pub const fn with_repr(self, repr: MonthRepr) -> Self {
332        Self { repr, ..self }
333    }
334
335    /// Set whether the value is case sensitive when parsing.
336    #[inline]
337    #[must_use = "this returns the result of the operation, without modifying the original"]
338    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
339        Self {
340            case_sensitive,
341            ..self
342        }
343    }
344}
345
346/// Ordinal day of the year.
347#[non_exhaustive]
348#[derive(Debug, Clone, Copy, PartialEq, Eq)]
349pub struct Ordinal {
350    /// The padding to obtain the minimum width.
351    pub padding: Padding,
352}
353
354impl Ordinal {
355    /// Set the padding type.
356    #[inline]
357    #[must_use = "this returns the result of the operation, without modifying the original"]
358    pub const fn with_padding(self, padding: Padding) -> Self {
359        Self { padding }
360    }
361}
362
363/// The representation used for the day of the week.
364#[non_exhaustive]
365#[deprecated(
366    since = "0.3.48",
367    note = "used only in the deprecated `Weekday` component"
368)]
369#[derive(Debug, Clone, Copy, PartialEq, Eq)]
370pub enum WeekdayRepr {
371    /// The short form of the weekday (e.g. "Mon").
372    Short,
373    /// The long form of the weekday (e.g. "Monday").
374    Long,
375    /// A numerical representation using Sunday as the first day of the week.
376    ///
377    /// Sunday is either 0 or 1, depending on the other modifier's value.
378    Sunday,
379    /// A numerical representation using Monday as the first day of the week.
380    ///
381    /// Monday is either 0 or 1, depending on the other modifier's value.
382    Monday,
383}
384
385/// Day of the week using the short form of the weekday (e.g. "Mon").
386#[derive(Debug, Clone, Copy, PartialEq, Eq)]
387pub struct WeekdayShort {
388    /// Is the value case sensitive when parsing?
389    pub(crate) case_sensitive: bool,
390}
391
392impl WeekdayShort {
393    /// Set whether the value is case sensitive when parsing.
394    #[inline]
395    #[must_use = "this returns the result of the operation, without modifying the original"]
396    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
397        Self { case_sensitive }
398    }
399}
400
401/// Day of the week using the long form of the weekday (e.g. "Monday").
402#[derive(Debug, Clone, Copy, PartialEq, Eq)]
403pub struct WeekdayLong {
404    /// Is the value case sensitive when parsing?
405    pub(crate) case_sensitive: bool,
406}
407
408impl WeekdayLong {
409    /// Set whether the value is case sensitive when parsing.
410    #[inline]
411    #[must_use = "this returns the result of the operation, without modifying the original"]
412    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
413        Self { case_sensitive }
414    }
415}
416
417/// Day of the week using a numerical representation with Sunday as the first day of the week.
418#[derive(Debug, Clone, Copy, PartialEq, Eq)]
419pub struct WeekdaySunday {
420    /// Is the value zero or one-indexed?
421    pub(crate) one_indexed: bool,
422}
423
424impl WeekdaySunday {
425    /// Set whether the value is one-indexed.
426    #[inline]
427    #[must_use = "this returns the result of the operation, without modifying the original"]
428    pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
429        Self { one_indexed }
430    }
431}
432
433/// Day of the week using a numerical representation with Monday as the first day of the week.
434#[derive(Debug, Clone, Copy, PartialEq, Eq)]
435pub struct WeekdayMonday {
436    /// Is the value zero or one-indexed?
437    pub(crate) one_indexed: bool,
438}
439
440impl WeekdayMonday {
441    /// Set whether the value is one-indexed.
442    #[inline]
443    #[must_use = "this returns the result of the operation, without modifying the original"]
444    pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
445        Self { one_indexed }
446    }
447}
448
449/// Day of the week.
450#[non_exhaustive]
451#[allow(deprecated)]
452#[deprecated(
453    since = "0.3.48",
454    note = "use `WeekdayShort`, `WeekdayLong`, `WeekdaySunday`, or `WeekdayMonday` instead"
455)]
456#[derive(Debug, Clone, Copy, PartialEq, Eq)]
457pub struct Weekday {
458    /// What form of representation should be used?
459    pub repr: WeekdayRepr,
460    /// When using a numerical representation, should it be zero or one-indexed?
461    pub one_indexed: bool,
462    /// Is the value case sensitive when parsing?
463    pub case_sensitive: bool,
464}
465
466#[expect(deprecated)]
467impl Weekday {
468    /// Set the manner in which the weekday is represented.
469    #[inline]
470    #[must_use = "this returns the result of the operation, without modifying the original"]
471    pub const fn with_repr(self, repr: WeekdayRepr) -> Self {
472        Self { repr, ..self }
473    }
474
475    /// Set whether the value is one-indexed when using a numerical representation.
476    #[inline]
477    #[must_use = "this returns the result of the operation, without modifying the original"]
478    pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
479        Self {
480            one_indexed,
481            ..self
482        }
483    }
484
485    /// Set whether the value is case sensitive when parsing.
486    #[inline]
487    #[must_use = "this returns the result of the operation, without modifying the original"]
488    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
489        Self {
490            case_sensitive,
491            ..self
492        }
493    }
494}
495
496/// The representation used for the week number.
497#[non_exhaustive]
498#[deprecated(
499    since = "0.3.48",
500    note = "used only in the deprecated `WeekNumber` component"
501)]
502#[derive(Debug, Clone, Copy, PartialEq, Eq)]
503pub enum WeekNumberRepr {
504    /// Week 1 is the week that contains January 4.
505    Iso,
506    /// Week 1 begins on the first Sunday of the calendar year.
507    Sunday,
508    /// Week 1 begins on the first Monday of the calendar year.
509    Monday,
510}
511
512/// Week within the year using the ISO week calendar.
513///
514/// Week 1 is the week that contains January 4. All weeks begin on a Monday.
515#[derive(Debug, Clone, Copy, PartialEq, Eq)]
516pub struct WeekNumberIso {
517    /// The padding to obtain the minimum width.
518    pub padding: Padding,
519}
520
521impl WeekNumberIso {
522    /// Set the padding type.
523    #[inline]
524    #[must_use = "this returns the result of the operation, without modifying the original"]
525    pub const fn with_padding(self, padding: Padding) -> Self {
526        Self { padding }
527    }
528}
529
530/// Week within the calendar year.
531///
532/// Week 1 begins on the first Sunday of the calendar year.
533#[derive(Debug, Clone, Copy, PartialEq, Eq)]
534pub struct WeekNumberSunday {
535    /// The padding to obtain the minimum width.
536    pub padding: Padding,
537}
538
539impl WeekNumberSunday {
540    /// Set the padding type.
541    #[inline]
542    #[must_use = "this returns the result of the operation, without modifying the original"]
543    pub const fn with_padding(self, padding: Padding) -> Self {
544        Self { padding }
545    }
546}
547
548/// Week within the calendar year.
549///
550/// Week 1 begins on the first Monday of the calendar year.
551#[derive(Debug, Clone, Copy, PartialEq, Eq)]
552pub struct WeekNumberMonday {
553    /// The padding to obtain the minimum width.
554    pub padding: Padding,
555}
556
557impl WeekNumberMonday {
558    /// Set the padding type.
559    #[inline]
560    #[must_use = "this returns the result of the operation, without modifying the original"]
561    pub const fn with_padding(self, padding: Padding) -> Self {
562        Self { padding }
563    }
564}
565
566/// Week within the year.
567#[non_exhaustive]
568#[allow(deprecated)]
569#[deprecated(
570    since = "0.3.48",
571    note = "use `WeekNumberIso`, `WeekNumberSunday`, or `WeekNumberMonday` instead"
572)]
573#[derive(Debug, Clone, Copy, PartialEq, Eq)]
574pub struct WeekNumber {
575    /// The padding to obtain the minimum width.
576    pub padding: Padding,
577    /// What kind of representation should be used?
578    pub repr: WeekNumberRepr,
579}
580
581#[expect(deprecated)]
582impl WeekNumber {
583    /// Set the padding type.
584    #[inline]
585    #[must_use = "this returns the result of the operation, without modifying the original"]
586    pub const fn with_padding(self, padding: Padding) -> Self {
587        Self { padding, ..self }
588    }
589
590    /// Set the manner in which the week number is represented.
591    #[inline]
592    #[must_use = "this returns the result of the operation, without modifying the original"]
593    pub const fn with_repr(self, repr: WeekNumberRepr) -> Self {
594        Self { repr, ..self }
595    }
596}
597
598/// The representation used for a year value.
599#[non_exhaustive]
600#[deprecated(
601    since = "0.3.48",
602    note = "used only in the deprecated `Year` component"
603)]
604#[derive(Debug, Clone, Copy, PartialEq, Eq)]
605pub enum YearRepr {
606    /// The full value of the year.
607    Full,
608    /// All digits except the last two. Includes the sign, if any.
609    Century,
610    /// Only the last two digits of the year.
611    LastTwo,
612}
613
614/// The range of years that are supported.
615///
616/// This modifier has no effect when the year repr is [`LastTwo`](YearRepr::LastTwo).
617#[non_exhaustive]
618#[deprecated(
619    since = "0.3.48",
620    note = "used only in the deprecated `Year` component"
621)]
622#[derive(Debug, Clone, Copy, PartialEq, Eq)]
623pub enum YearRange {
624    /// Years between -9999 and 9999 are supported.
625    Standard,
626    /// Years between -999_999 and 999_999 are supported, with the sign being required if the year
627    /// contains more than four digits.
628    ///
629    /// If the `large-dates` feature is not enabled, this variant is equivalent to `Standard`.
630    Extended,
631}
632
633/// Year of the date. All digits are included, the calendar year is used, and the range of years
634/// supported is ±999,999.
635#[derive(Debug, Clone, Copy, PartialEq, Eq)]
636pub struct CalendarYearFullExtendedRange {
637    /// The padding to obtain the minimum width.
638    pub(crate) padding: Padding,
639    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
640    /// necessary.
641    pub(crate) sign_is_mandatory: bool,
642}
643
644impl CalendarYearFullExtendedRange {
645    /// Set the padding type.
646    #[inline]
647    #[must_use = "this returns the result of the operation, without modifying the original"]
648    pub const fn with_padding(self, padding: Padding) -> Self {
649        Self { padding, ..self }
650    }
651
652    /// Set whether the `+` sign is mandatory for non-negative years with more than four digits.
653    #[inline]
654    #[must_use = "this returns the result of the operation, without modifying the original"]
655    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
656        Self {
657            sign_is_mandatory,
658            ..self
659        }
660    }
661}
662
663/// Year of the date. All digits are included, the calendar year is used, and the range of years
664/// supported is ±9,999.
665#[derive(Debug, Clone, Copy, PartialEq, Eq)]
666pub struct CalendarYearFullStandardRange {
667    /// The padding to obtain the minimum width.
668    pub(crate) padding: Padding,
669    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
670    /// necessary.
671    pub(crate) sign_is_mandatory: bool,
672}
673
674impl CalendarYearFullStandardRange {
675    /// Set the padding type.
676    #[inline]
677    #[must_use = "this returns the result of the operation, without modifying the original"]
678    pub const fn with_padding(self, padding: Padding) -> Self {
679        Self { padding, ..self }
680    }
681
682    /// Set whether the `+` sign is present on non-negative years.
683    #[inline]
684    #[must_use = "this returns the result of the operation, without modifying the original"]
685    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
686        Self {
687            sign_is_mandatory,
688            ..self
689        }
690    }
691}
692
693/// Year of the date. All digits are included, the ISO week-numbering year is used, and the range of
694/// years supported is ±999,999.
695#[derive(Debug, Clone, Copy, PartialEq, Eq)]
696pub struct IsoYearFullExtendedRange {
697    /// The padding to obtain the minimum width.
698    pub(crate) padding: Padding,
699    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
700    /// necessary.
701    pub(crate) sign_is_mandatory: bool,
702}
703
704impl IsoYearFullExtendedRange {
705    /// Set the padding type.
706    #[inline]
707    #[must_use = "this returns the result of the operation, without modifying the original"]
708    pub const fn with_padding(self, padding: Padding) -> Self {
709        Self { padding, ..self }
710    }
711
712    /// Set whether the `+` sign is mandatory for non-negative years with more than four digits.
713    #[inline]
714    #[must_use = "this returns the result of the operation, without modifying the original"]
715    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
716        Self {
717            sign_is_mandatory,
718            ..self
719        }
720    }
721}
722
723/// Year of the date. All digits are included, the ISO week-numbering year is used, and the range of
724/// supported is ±9,999.
725#[derive(Debug, Clone, Copy, PartialEq, Eq)]
726pub struct IsoYearFullStandardRange {
727    /// The padding to obtain the minimum width.
728    pub(crate) padding: Padding,
729    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
730    /// necessary.
731    pub(crate) sign_is_mandatory: bool,
732}
733
734impl IsoYearFullStandardRange {
735    /// Set the padding type.
736    #[inline]
737    #[must_use = "this returns the result of the operation, without modifying the original"]
738    pub const fn with_padding(self, padding: Padding) -> Self {
739        Self { padding, ..self }
740    }
741
742    /// Set whether the `+` sign is present on non-negative years.
743    #[inline]
744    #[must_use = "this returns the result of the operation, without modifying the original"]
745    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
746        Self {
747            sign_is_mandatory,
748            ..self
749        }
750    }
751}
752
753/// Year of the date. Only the century is included (i.e. all digits except the last two), the
754/// calendar year is used, and the range of years supported is ±999,999.
755#[derive(Debug, Clone, Copy, PartialEq, Eq)]
756pub struct CalendarYearCenturyExtendedRange {
757    /// The padding to obtain the minimum width.
758    pub(crate) padding: Padding,
759    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
760    /// necessary.
761    pub(crate) sign_is_mandatory: bool,
762}
763
764impl CalendarYearCenturyExtendedRange {
765    /// Set the padding type.
766    #[inline]
767    #[must_use = "this returns the result of the operation, without modifying the original"]
768    pub const fn with_padding(self, padding: Padding) -> Self {
769        Self { padding, ..self }
770    }
771
772    /// Set whether the `+` sign is mandatory for non-negative years with more than four digits.
773    #[inline]
774    #[must_use = "this returns the result of the operation, without modifying the original"]
775    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
776        Self {
777            sign_is_mandatory,
778            ..self
779        }
780    }
781}
782
783/// Year of the date. Only the century is included (i.e. all digits except the last two), the
784/// calendar year is used, and the range of years supported is ±9,999.
785#[derive(Debug, Clone, Copy, PartialEq, Eq)]
786pub struct CalendarYearCenturyStandardRange {
787    /// The padding to obtain the minimum width.
788    pub(crate) padding: Padding,
789    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
790    /// necessary.
791    pub(crate) sign_is_mandatory: bool,
792}
793
794impl CalendarYearCenturyStandardRange {
795    /// Set the padding type.
796    #[inline]
797    #[must_use = "this returns the result of the operation, without modifying the original"]
798    pub const fn with_padding(self, padding: Padding) -> Self {
799        Self { padding, ..self }
800    }
801
802    /// Set whether the `+` sign is present on non-negative years.
803    #[inline]
804    #[must_use = "this returns the result of the operation, without modifying the original"]
805    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
806        Self {
807            sign_is_mandatory,
808            ..self
809        }
810    }
811}
812
813/// Year of the date. Only the century is included (i.e. all digits except the last two), the ISO
814/// week-numbering year is used, and the range of years supported is ±999,999.
815#[derive(Debug, Clone, Copy, PartialEq, Eq)]
816pub struct IsoYearCenturyExtendedRange {
817    /// The padding to obtain the minimum width.
818    pub(crate) padding: Padding,
819    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
820    /// necessary.
821    pub(crate) sign_is_mandatory: bool,
822}
823
824impl IsoYearCenturyExtendedRange {
825    /// Set the padding type.
826    #[inline]
827    #[must_use = "this returns the result of the operation, without modifying the original"]
828    pub const fn with_padding(self, padding: Padding) -> Self {
829        Self { padding, ..self }
830    }
831
832    /// Set whether the `+` sign is mandatory for non-negative years with more than four digits.
833    #[inline]
834    #[must_use = "this returns the result of the operation, without modifying the original"]
835    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
836        Self {
837            sign_is_mandatory,
838            ..self
839        }
840    }
841}
842
843/// Year of the date. Only the century is included (i.e. all digits except the last two), the ISO
844/// week-numbering year is used, and the range of years supported is ±9,999.
845#[derive(Debug, Clone, Copy, PartialEq, Eq)]
846pub struct IsoYearCenturyStandardRange {
847    /// The padding to obtain the minimum width.
848    pub(crate) padding: Padding,
849    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
850    /// necessary.
851    pub(crate) sign_is_mandatory: bool,
852}
853
854impl IsoYearCenturyStandardRange {
855    /// Set the padding type.
856    #[inline]
857    #[must_use = "this returns the result of the operation, without modifying the original"]
858    pub const fn with_padding(self, padding: Padding) -> Self {
859        Self { padding, ..self }
860    }
861
862    /// Set whether the `+` sign is present on non-negative years.
863    #[inline]
864    #[must_use = "this returns the result of the operation, without modifying the original"]
865    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
866        Self {
867            sign_is_mandatory,
868            ..self
869        }
870    }
871}
872
873/// Year of the date. Only the last two digits are included, and the calendar year is used.
874#[non_exhaustive]
875#[derive(Debug, Clone, Copy, PartialEq, Eq)]
876pub struct CalendarYearLastTwo {
877    /// The padding to obtain the minimum width.
878    pub(crate) padding: Padding,
879}
880
881impl CalendarYearLastTwo {
882    /// Set the padding type.
883    #[inline]
884    #[must_use = "this returns the result of the operation, without modifying the original"]
885    pub const fn with_padding(self, padding: Padding) -> Self {
886        Self { padding }
887    }
888}
889
890/// Year of the date. Only the last two digits are included, and the ISO week-numbering year is
891/// used.
892#[non_exhaustive]
893#[derive(Debug, Clone, Copy, PartialEq, Eq)]
894pub struct IsoYearLastTwo {
895    /// The padding to obtain the minimum width.
896    pub(crate) padding: Padding,
897}
898
899impl IsoYearLastTwo {
900    /// Set the padding type.
901    #[inline]
902    #[must_use = "this returns the result of the operation, without modifying the original"]
903    pub const fn with_padding(self, padding: Padding) -> Self {
904        Self { padding }
905    }
906}
907
908/// Year of the date.
909#[non_exhaustive]
910#[allow(deprecated)]
911#[deprecated(
912    since = "0.3.48",
913    note = "use one of the various `Year*` components instead"
914)]
915#[derive(Debug, Clone, Copy, PartialEq, Eq)]
916pub struct Year {
917    /// The padding to obtain the minimum width.
918    pub padding: Padding,
919    /// What kind of representation should be used?
920    pub repr: YearRepr,
921    /// What range of years is supported?
922    pub range: YearRange,
923    /// Whether the value is based on the ISO week number or the Gregorian calendar.
924    pub iso_week_based: bool,
925    /// Whether the `+` sign is present when a non-negative year contains fewer digits than
926    /// necessary.
927    pub sign_is_mandatory: bool,
928}
929
930#[expect(deprecated)]
931impl Year {
932    /// Set the padding type.
933    #[inline]
934    #[must_use = "this returns the result of the operation, without modifying the original"]
935    pub const fn with_padding(self, padding: Padding) -> Self {
936        Self { padding, ..self }
937    }
938
939    /// Set the manner in which the year is represented.
940    #[inline]
941    #[must_use = "this returns the result of the operation, without modifying the original"]
942    pub const fn with_repr(self, repr: YearRepr) -> Self {
943        Self { repr, ..self }
944    }
945
946    /// Set the range of years that are supported.
947    #[inline]
948    #[must_use = "this returns the result of the operation, without modifying the original"]
949    pub const fn with_range(self, range: YearRange) -> Self {
950        Self { range, ..self }
951    }
952
953    /// Set whether the year is based on the ISO week number.
954    #[inline]
955    #[must_use = "this returns the result of the operation, without modifying the original"]
956    pub const fn with_iso_week_based(self, iso_week_based: bool) -> Self {
957        Self {
958            iso_week_based,
959            ..self
960        }
961    }
962
963    /// Set whether the `+` sign is mandatory for positive years with fewer than five digits.
964    #[inline]
965    #[must_use = "this returns the result of the operation, without modifying the original"]
966    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
967        Self {
968            sign_is_mandatory,
969            ..self
970        }
971    }
972}
973
974/// Hour of the day using a 12-hour clock.
975#[derive(Debug, Clone, Copy, PartialEq, Eq)]
976pub struct Hour12 {
977    /// The padding to obtain the minimum width.
978    pub(crate) padding: Padding,
979}
980
981impl Hour12 {
982    /// Set the padding type.
983    #[inline]
984    #[must_use = "this returns the result of the operation, without modifying the original"]
985    pub const fn with_padding(self, padding: Padding) -> Self {
986        Self { padding }
987    }
988}
989
990/// Hour of the day using a 24-hour clock.
991#[derive(Debug, Clone, Copy, PartialEq, Eq)]
992pub struct Hour24 {
993    /// The padding to obtain the minimum width.
994    pub(crate) padding: Padding,
995}
996
997impl Hour24 {
998    /// Set the padding type.
999    #[inline]
1000    #[must_use = "this returns the result of the operation, without modifying the original"]
1001    pub const fn with_padding(self, padding: Padding) -> Self {
1002        Self { padding }
1003    }
1004}
1005
1006/// Hour of the day.
1007#[non_exhaustive]
1008#[deprecated(since = "0.3.48", note = "use `Hour12` or `Hour24` instead")]
1009#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1010pub struct Hour {
1011    /// The padding to obtain the minimum width.
1012    pub padding: Padding,
1013    /// Is the hour displayed using a 12 or 24-hour clock?
1014    pub is_12_hour_clock: bool,
1015}
1016
1017#[expect(deprecated)]
1018impl Hour {
1019    /// Set the padding type.
1020    #[inline]
1021    #[must_use = "this returns the result of the operation, without modifying the original"]
1022    pub const fn with_padding(self, padding: Padding) -> Self {
1023        Self { padding, ..self }
1024    }
1025
1026    /// Set whether the hour uses a 12-hour clock.
1027    #[inline]
1028    #[must_use = "this returns the result of the operation, without modifying the original"]
1029    pub const fn with_is_12_hour_clock(self, is_12_hour_clock: bool) -> Self {
1030        Self {
1031            is_12_hour_clock,
1032            ..self
1033        }
1034    }
1035}
1036
1037/// Minute within the hour.
1038#[non_exhaustive]
1039#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1040pub struct Minute {
1041    /// The padding to obtain the minimum width.
1042    pub padding: Padding,
1043}
1044
1045impl Minute {
1046    /// Set the padding type.
1047    #[inline]
1048    #[must_use = "this returns the result of the operation, without modifying the original"]
1049    pub const fn with_padding(self, padding: Padding) -> Self {
1050        Self { padding }
1051    }
1052}
1053
1054/// AM/PM part of the time.
1055#[non_exhaustive]
1056#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1057pub struct Period {
1058    /// Is the period uppercase or lowercase?
1059    pub is_uppercase: bool,
1060    /// Is the value case sensitive when parsing?
1061    ///
1062    /// Note that when `false`, the `is_uppercase` field has no effect on parsing behavior.
1063    pub case_sensitive: bool,
1064}
1065
1066impl Period {
1067    /// Set whether the period is uppercase.
1068    #[inline]
1069    #[must_use = "this returns the result of the operation, without modifying the original"]
1070    pub const fn with_is_uppercase(self, is_uppercase: bool) -> Self {
1071        Self {
1072            is_uppercase,
1073            ..self
1074        }
1075    }
1076
1077    /// Set whether the value is case sensitive when parsing.
1078    #[inline]
1079    #[must_use = "this returns the result of the operation, without modifying the original"]
1080    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
1081        Self {
1082            case_sensitive,
1083            ..self
1084        }
1085    }
1086}
1087
1088/// Second within the minute.
1089#[non_exhaustive]
1090#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1091pub struct Second {
1092    /// The padding to obtain the minimum width.
1093    pub padding: Padding,
1094}
1095
1096impl Second {
1097    /// Set the padding type.
1098    #[inline]
1099    #[must_use = "this returns the result of the operation, without modifying the original"]
1100    pub const fn with_padding(self, padding: Padding) -> Self {
1101        Self { padding }
1102    }
1103}
1104
1105/// The number of digits present in a subsecond representation.
1106#[non_exhaustive]
1107#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1108pub enum SubsecondDigits {
1109    /// Exactly one digit.
1110    One,
1111    /// Exactly two digits.
1112    Two,
1113    /// Exactly three digits.
1114    Three,
1115    /// Exactly four digits.
1116    Four,
1117    /// Exactly five digits.
1118    Five,
1119    /// Exactly six digits.
1120    Six,
1121    /// Exactly seven digits.
1122    Seven,
1123    /// Exactly eight digits.
1124    Eight,
1125    /// Exactly nine digits.
1126    Nine,
1127    /// Any number of digits (up to nine) that is at least one. When formatting, the minimum digits
1128    /// necessary will be used.
1129    OneOrMore,
1130}
1131
1132/// Subsecond within the second.
1133#[non_exhaustive]
1134#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1135pub struct Subsecond {
1136    /// How many digits are present in the component?
1137    pub digits: SubsecondDigits,
1138}
1139
1140impl Subsecond {
1141    /// Set the number of digits present in the subsecond representation.
1142    #[inline]
1143    #[must_use = "this returns the result of the operation, without modifying the original"]
1144    pub const fn with_digits(self, digits: SubsecondDigits) -> Self {
1145        Self { digits }
1146    }
1147}
1148
1149/// Hour of the UTC offset.
1150#[non_exhaustive]
1151#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1152pub struct OffsetHour {
1153    /// Whether the `+` sign is present on positive values.
1154    pub sign_is_mandatory: bool,
1155    /// The padding to obtain the minimum width.
1156    pub padding: Padding,
1157}
1158
1159impl OffsetHour {
1160    /// Set whether the `+` sign is mandatory for positive values.
1161    #[inline]
1162    #[must_use = "this returns the result of the operation, without modifying the original"]
1163    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1164        Self {
1165            sign_is_mandatory,
1166            ..self
1167        }
1168    }
1169
1170    /// Set the padding type.
1171    #[inline]
1172    #[must_use = "this returns the result of the operation, without modifying the original"]
1173    pub const fn with_padding(self, padding: Padding) -> Self {
1174        Self { padding, ..self }
1175    }
1176}
1177
1178/// Minute within the hour of the UTC offset.
1179#[non_exhaustive]
1180#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1181pub struct OffsetMinute {
1182    /// The padding to obtain the minimum width.
1183    pub padding: Padding,
1184}
1185
1186impl OffsetMinute {
1187    /// Set the padding type.
1188    #[inline]
1189    #[must_use = "this returns the result of the operation, without modifying the original"]
1190    pub const fn with_padding(self, padding: Padding) -> Self {
1191        Self { padding }
1192    }
1193}
1194
1195/// Second within the minute of the UTC offset.
1196#[non_exhaustive]
1197#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1198pub struct OffsetSecond {
1199    /// The padding to obtain the minimum width.
1200    pub padding: Padding,
1201}
1202
1203impl OffsetSecond {
1204    /// Set the padding type.
1205    #[inline]
1206    #[must_use = "this returns the result of the operation, without modifying the original"]
1207    pub const fn with_padding(self, padding: Padding) -> Self {
1208        Self { padding }
1209    }
1210}
1211
1212/// Type of padding to ensure a minimum width.
1213#[non_exhaustive]
1214#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1215pub enum Padding {
1216    /// A space character (` `) should be used as padding.
1217    Space,
1218    /// A zero character (`0`) should be used as padding.
1219    Zero,
1220    /// There is no padding. This can result in a width below the otherwise minimum number of
1221    /// characters.
1222    None,
1223}
1224
1225/// Ignore some number of bytes.
1226///
1227/// This has no effect when formatting.
1228#[non_exhaustive]
1229#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1230pub struct Ignore {
1231    /// The number of bytes to ignore.
1232    pub count: NonZero<u16>,
1233}
1234
1235// Needed as `Default` is deliberately not implemented for `Ignore`. The number of bytes to ignore
1236// must be explicitly provided.
1237impl Ignore {
1238    /// Create an instance of `Ignore` with the provided number of bytes to ignore.
1239    #[inline]
1240    pub const fn count(count: NonZero<u16>) -> Self {
1241        Self { count }
1242    }
1243
1244    /// Set the number of bytes to ignore.
1245    #[inline]
1246    #[must_use = "this returns the result of the operation, without modifying the original"]
1247    pub const fn with_count(self, count: NonZero<u16>) -> Self {
1248        Self { count }
1249    }
1250}
1251
1252/// The precision of a Unix timestamp.
1253#[non_exhaustive]
1254#[deprecated(
1255    since = "0.3.48",
1256    note = "only used in the deprecated `UnixTimestamp` component"
1257)]
1258#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1259pub enum UnixTimestampPrecision {
1260    /// Seconds since the Unix epoch.
1261    Second,
1262    /// Milliseconds since the Unix epoch.
1263    Millisecond,
1264    /// Microseconds since the Unix epoch.
1265    Microsecond,
1266    /// Nanoseconds since the Unix epoch.
1267    Nanosecond,
1268}
1269
1270/// A Unix timestamp in seconds.
1271#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1272pub struct UnixTimestampSecond {
1273    /// Whether the `+` sign must be present for a non-negative timestamp.
1274    pub(crate) sign_is_mandatory: bool,
1275}
1276
1277impl UnixTimestampSecond {
1278    /// Set whether the `+` sign is mandatory for non-negative timestamps.
1279    #[inline]
1280    #[must_use = "this returns the result of the operation, without modifying the original"]
1281    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1282        Self { sign_is_mandatory }
1283    }
1284}
1285
1286/// A Unix timestamp in milliseconds.
1287#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1288pub struct UnixTimestampMillisecond {
1289    /// Whether the `+` sign must be present for a non-negative timestamp.
1290    pub(crate) sign_is_mandatory: bool,
1291}
1292
1293impl UnixTimestampMillisecond {
1294    /// Set whether the `+` sign is mandatory for non-negative timestamps.
1295    #[inline]
1296    #[must_use = "this returns the result of the operation, without modifying the original"]
1297    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1298        Self { sign_is_mandatory }
1299    }
1300}
1301
1302/// A Unix timestamp in microseconds.
1303#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1304pub struct UnixTimestampMicrosecond {
1305    /// Whether the `+` sign must be present for a non-negative timestamp.
1306    pub(crate) sign_is_mandatory: bool,
1307}
1308
1309impl UnixTimestampMicrosecond {
1310    /// Set whether the `+` sign is mandatory for non-negative timestamps.
1311    #[inline]
1312    #[must_use = "this returns the result of the operation, without modifying the original"]
1313    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1314        Self { sign_is_mandatory }
1315    }
1316}
1317
1318/// A Unix timestamp in nanoseconds.
1319#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1320pub struct UnixTimestampNanosecond {
1321    /// Whether the `+` sign must be present for a non-negative timestamp.
1322    pub(crate) sign_is_mandatory: bool,
1323}
1324
1325impl UnixTimestampNanosecond {
1326    /// Set whether the `+` sign is mandatory for non-negative timestamps.
1327    #[inline]
1328    #[must_use = "this returns the result of the operation, without modifying the original"]
1329    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1330        Self { sign_is_mandatory }
1331    }
1332}
1333
1334/// A Unix timestamp.
1335#[non_exhaustive]
1336#[allow(deprecated)]
1337#[deprecated(
1338    since = "0.3.48",
1339    note = "use `UnixTimestampSeconds`, `UnixTimestampMilliseconds`, `UnixTimestampMicroseconds`, \
1340            or `UnixTimestampNanoseconds` instead"
1341)]
1342#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1343pub struct UnixTimestamp {
1344    /// The precision of the timestamp.
1345    pub precision: UnixTimestampPrecision,
1346    /// Whether the `+` sign must be present for a non-negative timestamp.
1347    pub sign_is_mandatory: bool,
1348}
1349
1350#[expect(deprecated)]
1351impl UnixTimestamp {
1352    /// Set the precision of the timestamp.
1353    #[inline]
1354    #[must_use = "this returns the result of the operation, without modifying the original"]
1355    pub const fn with_precision(self, precision: UnixTimestampPrecision) -> Self {
1356        Self { precision, ..self }
1357    }
1358
1359    /// Set whether the `+` sign is mandatory for non-negative timestamps.
1360    #[inline]
1361    #[must_use = "this returns the result of the operation, without modifying the original"]
1362    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
1363        Self {
1364            sign_is_mandatory,
1365            ..self
1366        }
1367    }
1368}
1369
1370/// Whether trailing input after the declared end is permitted.
1371#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1372pub enum TrailingInput {
1373    /// Trailing input is not permitted and will cause an error.
1374    Prohibit,
1375    /// Trailing input is permitted but discarded.
1376    Discard,
1377}
1378
1379/// The end of input.
1380#[non_exhaustive]
1381#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1382pub struct End {
1383    /// How to handle any input after this component.
1384    pub(crate) trailing_input: TrailingInput,
1385}
1386
1387impl End {
1388    /// Set how to handle any input after this component.
1389    #[inline]
1390    #[must_use = "this returns the result of the operation, without modifying the original"]
1391    pub const fn with_trailing_input(self, trailing_input: TrailingInput) -> Self {
1392        Self {
1393            trailing_input,
1394            ..self
1395        }
1396    }
1397}