etcd_rs/lease/
time_to_live.rs

1use crate::proto::etcdserverpb;
2use crate::{LeaseId, ResponseHeader};
3
4#[derive(Debug)]
5pub struct LeaseTimeToLiveRequest {
6    proto: crate::proto::etcdserverpb::LeaseTimeToLiveRequest,
7}
8
9impl LeaseTimeToLiveRequest {
10    /// Creates a new LeaseTimeToLiveRequest with the specified lease id.
11    pub fn new(id: LeaseId) -> Self {
12        Self {
13            proto: etcdserverpb::LeaseTimeToLiveRequest { id, keys: false },
14        }
15    }
16
17    /// Set custom lease ID.
18    pub fn with_id(mut self, id: LeaseId) -> Self {
19        self.proto.id = id;
20        self
21    }
22
23    pub fn with_keys(mut self, keys: bool) -> Self {
24        self.proto.keys = keys;
25        self
26    }
27}
28
29impl From<LeaseTimeToLiveRequest> for crate::proto::etcdserverpb::LeaseTimeToLiveRequest {
30    fn from(x: LeaseTimeToLiveRequest) -> Self {
31        x.proto
32    }
33}
34
35impl From<LeaseId> for LeaseTimeToLiveRequest {
36    fn from(lease_id: LeaseId) -> Self {
37        Self::new(lease_id)
38    }
39}
40
41#[derive(Debug)]
42pub struct LeaseTimeToLiveResponse {
43    pub header: ResponseHeader,
44    pub id: LeaseId,
45    pub ttl: i64,
46}
47
48impl From<crate::proto::etcdserverpb::LeaseTimeToLiveResponse> for LeaseTimeToLiveResponse {
49    fn from(proto: crate::proto::etcdserverpb::LeaseTimeToLiveResponse) -> Self {
50        Self {
51            header: From::from(proto.header.expect("must fetch header")),
52            id: proto.id,
53            ttl: proto.ttl,
54        }
55    }
56}