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

Open
Phoenix500526 opened this issue May 14, 2024 · 2 comments
Open

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

Phoenix500526 opened this issue May 14, 2024 · 2 comments
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.

@realtaobo
Copy link
Contributor

/assignme

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

No branches or pull requests

2 participants