Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor]: Remove request wrappers in xline-client #819

Closed
Phoenix500526 opened this issue May 14, 2024 · 5 comments · Fixed by #899
Closed

[Refactor]: Remove request wrappers in xline-client #819

Phoenix500526 opened this issue May 14, 2024 · 5 comments · Fixed by #899
Assignees
Labels
good first issue Good for newcomers

Comments

@Phoenix500526
Copy link
Collaborator

We implement some request wrappers in the xline-client crate, like

/// Xline/crates/xline-client/src/types/lock.rs
/// Request for `Lock`
#[derive(Debug, PartialEq)]
pub struct LockRequest {
    /// The inner request
    pub(crate) inner: xlineapi::LockRequest,
    /// The ttl of the lease that attached to the lock
    pub(crate) ttl: i64,
}

impl LockRequest {
    /// Creates a new `LockRequest`
    #[inline]
    #[must_use]
    pub fn new(name: impl Into<Vec<u8>>) -> Self {
        ...
    }

    /// Set lease.
    #[inline]
    #[must_use]
    pub const fn with_lease(mut self, lease: i64) -> Self {
        self.inner.lease = lease;
        self
    }

    /// Set session TTL.
    /// Will be ignored when lease id is set
    #[inline]
    #[must_use]
    pub const fn with_ttl(mut self, ttl: i64) -> Self {
        self.ttl = ttl;
        self
    }
}

Therefore, when we want to perform a lock operation by xline-client, we should write some code like this:

#[tokio::main]
async fn main() -> Result<()> {
     ...
     let lock_request = LockRequest::new("lock-test").with_ttl(50);
     // acquire a lock session
     let session = lock_client
         .lock(lock_request)
         .await?;
     ....
     Ok(())
}

This way is not very user-friendly. I prefer to use lock_client.lock("lock-test", 50) rather than lock_client.lock(LockRequest::new("lock-test").with_ttl(50)).

@Phoenix500526 Phoenix500526 added the good first issue Good for newcomers label May 14, 2024
Copy link

👋 Thanks for opening this issue!

Reply with the following command on its own line to get help or engage:

  • /contributing-agreement : to print Contributing Agreements.
  • /assignme : to assign this issue to you.

@poltao
Copy link
Contributor

poltao commented Jun 7, 2024

/assignme

Copy link

github-actions bot commented Jul 8, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jul 8, 2024
@poltao poltao removed their assignment Jul 8, 2024
@lxl66566
Copy link
Collaborator

lxl66566 commented Jul 8, 2024

/assignme

Copy link

github-actions bot commented Aug 8, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants