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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::proto::etcdserverpb;
use crate::ResponseHeader;

/// Request for revoking lease.
pub struct LeaseRevokeRequest {
    proto: etcdserverpb::LeaseRevokeRequest,
}

impl LeaseRevokeRequest {
    /// Creates a new LeaseRevokeRequest which will revoke the specified lease.
    pub fn new(id: u64) -> Self {
        let proto = etcdserverpb::LeaseRevokeRequest { id: id as i64 };

        Self { proto }
    }
}

impl Into<etcdserverpb::LeaseRevokeRequest> for LeaseRevokeRequest {
    fn into(self) -> etcdserverpb::LeaseRevokeRequest {
        self.proto
    }
}

/// Response for revoking lease.
#[derive(Debug)]
pub struct LeaseRevokeResponse {
    proto: etcdserverpb::LeaseRevokeResponse,
}

impl LeaseRevokeResponse {
    /// Takes the header out of response, leaving a `None` in its place.
    pub fn take_header(&mut self) -> Option<ResponseHeader> {
        match self.proto.header.take() {
            Some(header) => Some(From::from(header)),
            _ => None,
        }
    }
}

impl From<etcdserverpb::LeaseRevokeResponse> for LeaseRevokeResponse {
    fn from(resp: etcdserverpb::LeaseRevokeResponse) -> Self {
        Self { proto: resp }
    }
}