Made `Parsed` not fully destructible.
So that we can add more fields without breaking a major compatibility (as per RFC 1105).
This commit is contained in:
parent
36c45f2e02
commit
2b5553ee76
|
@ -358,9 +358,11 @@ fn test_parse() {
|
||||||
($fmt:expr, $items:expr; $err:tt) => (
|
($fmt:expr, $items:expr; $err:tt) => (
|
||||||
assert_eq!(parse_all($fmt, &$items), Err($err))
|
assert_eq!(parse_all($fmt, &$items), Err($err))
|
||||||
);
|
);
|
||||||
($fmt:expr, $items:expr; $($k:ident: $v:expr),*) => (
|
($fmt:expr, $items:expr; $($k:ident: $v:expr),*) => (#[allow(unused_mut)] {
|
||||||
assert_eq!(parse_all($fmt, &$items), Ok(Parsed { $($k: Some($v),)* ..Parsed::new() }))
|
let mut expected = Parsed::new();
|
||||||
);
|
$(expected.$k = Some($v);)*
|
||||||
|
assert_eq!(parse_all($fmt, &$items), Ok(expected))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty string
|
// empty string
|
||||||
|
|
|
@ -108,6 +108,9 @@ pub struct Parsed {
|
||||||
|
|
||||||
/// Offset from the local time to UTC, in seconds.
|
/// Offset from the local time to UTC, in seconds.
|
||||||
pub offset: Option<i32>,
|
pub offset: Option<i32>,
|
||||||
|
|
||||||
|
/// A dummy field to make this type not fully destructible (required for API stability).
|
||||||
|
_dummy: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if `old` is either empty or has the same value to `new` (i.e. "consistent"),
|
/// Checks if `old` is either empty or has the same value to `new` (i.e. "consistent"),
|
||||||
|
@ -121,14 +124,23 @@ fn set_if_consistent<T: PartialEq>(old: &mut Option<T>, new: T) -> ParseResult<(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Parsed {
|
||||||
|
fn default() -> Parsed {
|
||||||
|
Parsed {
|
||||||
|
year: None, year_div_100: None, year_mod_100: None, isoyear: None,
|
||||||
|
isoyear_div_100: None, isoyear_mod_100: None, month: None,
|
||||||
|
week_from_sun: None, week_from_mon: None, isoweek: None, weekday: None,
|
||||||
|
ordinal: None, day: None, hour_div_12: None, hour_mod_12: None, minute: None,
|
||||||
|
second: None, nanosecond: None, timestamp: None, offset: None,
|
||||||
|
_dummy: (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parsed {
|
impl Parsed {
|
||||||
/// Returns the initial value of parsed parts.
|
/// Returns the initial value of parsed parts.
|
||||||
pub fn new() -> Parsed {
|
pub fn new() -> Parsed {
|
||||||
Parsed { year: None, year_div_100: None, year_mod_100: None, isoyear: None,
|
Parsed::default()
|
||||||
isoyear_div_100: None, isoyear_mod_100: None, month: None,
|
|
||||||
week_from_sun: None, week_from_mon: None, isoweek: None, weekday: None,
|
|
||||||
ordinal: None, day: None, hour_div_12: None, hour_mod_12: None, minute: None,
|
|
||||||
second: None, nanosecond: None, timestamp: None, offset: None }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to set the [`year`](#structfield.year) field from given value.
|
/// Tries to set the [`year`](#structfield.year) field from given value.
|
||||||
|
|
Loading…
Reference in New Issue