Function aws_smithy_types::timeout::parse_str_as_timeout [−][src]
pub fn parse_str_as_timeout(
timeout: &str,
name: Cow<'static, str>,
set_by: Cow<'static, str>
) -> Result<Duration, TimeoutConfigError>
Expand description
Parse a given string as a Duration
that will be used to set a timeout. This will return an
error result if the given string is negative, infinite, equal to zero, NaN, or if the string
can’t be parsed as an f32
. The name
and set_by
fields are used to provide context when an
error occurs
Example
ⓘ
let duration = parse_str_as_timeout("8", "timeout".into(), "test_success".into()).unwrap();
assert_eq!(duration, Duration::from_secs_f32(8.0));
// This line will panic with "InvalidTimeout { name: "timeout", reason: "timeout must not be less than or equal to zero", set_by: "test_error" }"
let _ = parse_str_as_timeout("-1.0", "timeout".into(), "test_error".into()).unwrap();