azure_core/request_options/
timeout.rs
1use crate::{AppendToUrlQuery, Url};
2use std::time::Duration;
3
4#[derive(Debug, Clone, Copy)]
5pub struct Timeout(Duration);
6
7impl Timeout {
8 pub fn new(duration: Duration) -> Self {
9 Self(duration)
10 }
11}
12
13impl AppendToUrlQuery for Timeout {
14 fn append_to_url_query(&self, url: &mut Url) {
15 if url.query_pairs().any(|(k, _)| k == "timeout") {
16 return;
17 }
18
19 url.query_pairs_mut()
20 .append_pair("timeout", &format!("{}", self.0.as_secs()));
21 }
22}
23
24impl From<Duration> for Timeout {
25 fn from(d: Duration) -> Self {
26 Self(d)
27 }
28}