azure_core/request_options/
lease_duration.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::headers::{self, Header};
use std::time::Duration;

#[derive(Debug, Clone)]
pub enum LeaseDuration {
    Infinite,
    Seconds(u8),
}

impl Header for LeaseDuration {
    fn name(&self) -> headers::HeaderName {
        headers::LEASE_DURATION
    }

    fn value(&self) -> headers::HeaderValue {
        match self {
            LeaseDuration::Infinite => "-1".to_owned(),
            LeaseDuration::Seconds(seconds) => {
                format!("{seconds}")
            }
        }
        .into()
    }
}

impl From<Duration> for LeaseDuration {
    fn from(d: Duration) -> Self {
        LeaseDuration::Seconds(d.as_secs() as u8)
    }
}