etcd_client/namespace/
lease.rs

1use crate::error::Result;
2use crate::{LeaseClient, LeaseTimeToLiveOptions, LeaseTimeToLiveResponse};
3
4pub struct LeaseClientPrefix {
5    pfx: Vec<u8>,
6    lease: LeaseClient,
7}
8
9impl LeaseClientPrefix {
10    /// Wrap a Lease interface to filter for only keys with a prefix
11    /// and remove that prefix when fetching attached keys through TimeToLive.
12    pub fn new(lease: LeaseClient, pfx: Vec<u8>) -> Self {
13        Self { pfx, lease }
14    }
15
16    pub async fn time_to_live(
17        &mut self,
18        id: i64,
19        options: Option<LeaseTimeToLiveOptions>,
20    ) -> Result<LeaseTimeToLiveResponse> {
21        let mut resp = self.lease.time_to_live(id, options).await?;
22        resp.strip_keys_prefix(&self.pfx);
23        Ok(resp)
24    }
25}