Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

use i64 for lease ttl and LeaseId type for ttl request #81

Merged
merged 1 commit into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lease/grant.rs
Expand Up @@ -43,15 +43,15 @@ impl From<Duration> for LeaseGrantRequest {
pub struct LeaseGrantResponse {
pub header: ResponseHeader,
pub id: LeaseId,
pub ttl: u64,
pub ttl: i64,
}

impl From<crate::proto::etcdserverpb::LeaseGrantResponse> for LeaseGrantResponse {
fn from(proto: crate::proto::etcdserverpb::LeaseGrantResponse) -> Self {
Self {
header: From::from(proto.header.expect("must fetch header")),
id: proto.id,
ttl: proto.ttl as u64,
ttl: proto.ttl,
}
}
}
6 changes: 3 additions & 3 deletions src/lease/keep_alive.rs
Expand Up @@ -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 },
}
}
}
Expand All @@ -26,15 +26,15 @@ impl From<LeaseKeepAliveRequest> for crate::proto::etcdserverpb::LeaseKeepAliveR
pub struct LeaseKeepAliveResponse {
pub header: ResponseHeader,
pub id: LeaseId,
pub ttl: u64,
pub ttl: i64,
}

impl From<crate::proto::etcdserverpb::LeaseKeepAliveResponse> for LeaseKeepAliveResponse {
fn from(proto: crate::proto::etcdserverpb::LeaseKeepAliveResponse) -> Self {
Self {
header: From::from(proto.header.expect("must fetch header")),
id: proto.id,
ttl: proto.ttl as u64,
ttl: proto.ttl,
}
}
}
21 changes: 9 additions & 12 deletions src/lease/time_to_live.rs
Expand Up @@ -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
}

Expand All @@ -35,25 +32,25 @@ impl From<LeaseTimeToLiveRequest> for crate::proto::etcdserverpb::LeaseTimeToLiv
}
}

impl From<u64> for LeaseTimeToLiveRequest {
fn from(watch_id: u64) -> Self {
Self::new(watch_id)
impl From<LeaseId> for LeaseTimeToLiveRequest {
fn from(lease_id: LeaseId) -> Self {
Self::new(lease_id)
}
}

#[derive(Debug)]
pub struct LeaseTimeToLiveResponse {
pub header: ResponseHeader,
pub id: LeaseId,
pub ttl: u64,
pub ttl: i64,
}

impl From<crate::proto::etcdserverpb::LeaseTimeToLiveResponse> for LeaseTimeToLiveResponse {
fn from(proto: crate::proto::etcdserverpb::LeaseTimeToLiveResponse) -> Self {
Self {
header: From::from(proto.header.expect("must fetch header")),
id: proto.id,
ttl: proto.ttl as u64,
ttl: proto.ttl,
}
}
}