mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-30 06:21:56 +00:00
Mark SecondsFormat
as #[non_exhaustive]
Removes the current hack and replaces it with the proper attribute that's available since Rust 1.45. Co-developed-by: TennyZhuang <zty0826@gmail.com>
This commit is contained in:
parent
0a16a65541
commit
0c011dea8b
@ -47,6 +47,7 @@ mod tests;
|
||||
/// future, so exhaustive matching in external code is not recommended.
|
||||
///
|
||||
/// See the `TimeZone::to_rfc3339_opts` function for usage.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum SecondsFormat {
|
||||
/// Format whole seconds only, with no decimal point nor subseconds.
|
||||
@ -68,10 +69,6 @@ pub enum SecondsFormat {
|
||||
/// display all available non-zero sub-second digits. This corresponds to
|
||||
/// [Fixed::Nanosecond](format/enum.Fixed.html#variant.Nanosecond).
|
||||
AutoSi,
|
||||
|
||||
// Do not match against this.
|
||||
#[doc(hidden)]
|
||||
__NonExhaustive,
|
||||
}
|
||||
|
||||
/// ISO 8601 combined date and time with time zone.
|
||||
@ -699,8 +696,6 @@ where
|
||||
use crate::format::Pad::Zero;
|
||||
use crate::SecondsFormat::*;
|
||||
|
||||
debug_assert!(secform != __NonExhaustive, "Do not use __NonExhaustive!");
|
||||
|
||||
const PREFIX: &[Item<'static>] = &[
|
||||
Item::Numeric(Year, Zero),
|
||||
Item::Literal("-"),
|
||||
@ -721,7 +716,6 @@ where
|
||||
Micros => Some(Item::Fixed(Fixed::Nanosecond6)),
|
||||
Nanos => Some(Item::Fixed(Fixed::Nanosecond9)),
|
||||
AutoSi => Some(Item::Fixed(Fixed::Nanosecond)),
|
||||
__NonExhaustive => unreachable!(),
|
||||
};
|
||||
|
||||
let tzitem = Item::Fixed(if use_z {
|
||||
|
@ -693,14 +693,6 @@ fn test_rfc3339_opts() {
|
||||
assert_eq!(ut.to_rfc3339_opts(AutoSi, true), "2018-01-11T02:05:13.084660Z");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_rfc3339_opts_nonexhaustive() {
|
||||
use crate::SecondsFormat;
|
||||
let dt = Utc.with_ymd_and_hms(1999, 10, 9, 1, 2, 3).unwrap();
|
||||
dt.to_rfc3339_opts(SecondsFormat::__NonExhaustive, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_datetime_from_str() {
|
||||
assert_eq!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user