forked from Proxmox/proxmox
proxmox-time: time-span: implement FromStr
and deprecate 'parse_time_span' Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
42420d3a5e
commit
c77ab2c7e5
@ -225,7 +225,7 @@ fn test_calendar_event_weekday() -> Result<(), Error> {
|
||||
#[test]
|
||||
fn test_time_span_parser() -> Result<(), Error> {
|
||||
let test_value = |ts_str: &str, expect: f64| -> Result<(), Error> {
|
||||
let ts = parse_time_span(ts_str)?;
|
||||
let ts: TimeSpan = ts_str.parse()?;
|
||||
assert_eq!(f64::from(ts), expect, "{}", ts_str);
|
||||
Ok(())
|
||||
};
|
||||
|
@ -198,9 +198,18 @@ fn parse_time_unit(i: &str) -> IResult<&str, &str> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for TimeSpan {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(i: &str) -> Result<Self, Self::Err> {
|
||||
parse_complete_line("calendar event", i, parse_time_span_incomplete)
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a [TimeSpan]
|
||||
#[deprecated="Use std::str::FromStr trait instead."]
|
||||
pub fn parse_time_span(i: &str) -> Result<TimeSpan, Error> {
|
||||
parse_complete_line("time span", i, parse_time_span_incomplete)
|
||||
i.parse()
|
||||
}
|
||||
|
||||
fn parse_time_span_incomplete(mut i: &str) -> IResult<&str, TimeSpan> {
|
||||
@ -259,7 +268,7 @@ fn parse_time_span_incomplete(mut i: &str) -> IResult<&str, TimeSpan> {
|
||||
|
||||
/// Verify the format of the [TimeSpan]
|
||||
pub fn verify_time_span(i: &str) -> Result<(), Error> {
|
||||
parse_time_span(i)?;
|
||||
let _: TimeSpan = i.parse()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user