From 4aa1c729e16a52b228e168869ae1717205b5e8fc Mon Sep 17 00:00:00 2001 From: James Birtles Date: Tue, 15 Nov 2022 12:41:13 +0000 Subject: [PATCH] use i64 for lease ttl and LeaseId type for ttl request --- src/lease/grant.rs | 4 ++-- src/lease/keep_alive.rs | 6 +++--- src/lease/time_to_live.rs | 21 +++++++++------------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/lease/grant.rs b/src/lease/grant.rs index 8d3fa7d..6d15348 100644 --- a/src/lease/grant.rs +++ b/src/lease/grant.rs @@ -43,7 +43,7 @@ impl From for LeaseGrantRequest { pub struct LeaseGrantResponse { pub header: ResponseHeader, pub id: LeaseId, - pub ttl: u64, + pub ttl: i64, } impl From for LeaseGrantResponse { @@ -51,7 +51,7 @@ impl From for LeaseGrantResponse Self { header: From::from(proto.header.expect("must fetch header")), id: proto.id, - ttl: proto.ttl as u64, + ttl: proto.ttl, } } } diff --git a/src/lease/keep_alive.rs b/src/lease/keep_alive.rs index c9dfaef..672fb9f 100644 --- a/src/lease/keep_alive.rs +++ b/src/lease/keep_alive.rs @@ -11,7 +11,7 @@ impl LeaseKeepAliveRequest { /// Creates a new LeaseKeepAliveRequest which will refresh the specified lease. pub fn new(id: LeaseId) -> Self { Self { - proto: etcdserverpb::LeaseKeepAliveRequest { id: id as i64 }, + proto: etcdserverpb::LeaseKeepAliveRequest { id }, } } } @@ -26,7 +26,7 @@ impl From for crate::proto::etcdserverpb::LeaseKeepAliveR pub struct LeaseKeepAliveResponse { pub header: ResponseHeader, pub id: LeaseId, - pub ttl: u64, + pub ttl: i64, } impl From for LeaseKeepAliveResponse { @@ -34,7 +34,7 @@ impl From for LeaseKeepAlive Self { header: From::from(proto.header.expect("must fetch header")), id: proto.id, - ttl: proto.ttl as u64, + ttl: proto.ttl, } } } diff --git a/src/lease/time_to_live.rs b/src/lease/time_to_live.rs index 87768bb..2f61240 100644 --- a/src/lease/time_to_live.rs +++ b/src/lease/time_to_live.rs @@ -7,19 +7,16 @@ pub struct LeaseTimeToLiveRequest { } impl LeaseTimeToLiveRequest { - /// Creates a new LeaseGrantRequest with the specified TTL. - pub fn new(id: u64) -> Self { + /// Creates a new LeaseTimeToLiveRequest with the specified lease id. + pub fn new(id: LeaseId) -> Self { Self { - proto: etcdserverpb::LeaseTimeToLiveRequest { - id: id as i64, - keys: false, - }, + proto: etcdserverpb::LeaseTimeToLiveRequest { id, keys: false }, } } /// Set custom lease ID. pub fn with_id(mut self, id: LeaseId) -> Self { - self.proto.id = id as i64; + self.proto.id = id; self } @@ -35,9 +32,9 @@ impl From for crate::proto::etcdserverpb::LeaseTimeToLiv } } -impl From for LeaseTimeToLiveRequest { - fn from(watch_id: u64) -> Self { - Self::new(watch_id) +impl From for LeaseTimeToLiveRequest { + fn from(lease_id: LeaseId) -> Self { + Self::new(lease_id) } } @@ -45,7 +42,7 @@ impl From for LeaseTimeToLiveRequest { pub struct LeaseTimeToLiveResponse { pub header: ResponseHeader, pub id: LeaseId, - pub ttl: u64, + pub ttl: i64, } impl From for LeaseTimeToLiveResponse { @@ -53,7 +50,7 @@ impl From for LeaseTimeToLi Self { header: From::from(proto.header.expect("must fetch header")), id: proto.id, - ttl: proto.ttl as u64, + ttl: proto.ttl, } } }