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

Can Client derive Clone? #9

Open
enriquein opened this issue Sep 30, 2020 · 2 comments
Open

Can Client derive Clone? #9

enriquein opened this issue Sep 30, 2020 · 2 comments

Comments

@enriquein
Copy link

Thank you for your work on this library. I stumbled today into a situation where I'm required to pass a rustforce::Client within a closure inside an async function. The compiler complains that the reference I'm passing doesn't live long enough, but suggests that I use move. However, when I use move, it complains that Clone isn't implemented for Client. I was wondering if having Client not implement Clone was a deliberate design choice, or if perhaps it could be something that we could add to the library.

@tzmfreedom
Copy link
Owner

Sorry for my late reply 🙇‍♂️
It's not deliberate, and I think that having Client implement Clone is good idea.

I'm not familiar with rust, so I'd like to ask how to implement clonable client.
Is the following implementation correct?

#[derive(Clone)]
pub struct Client {
    http_client: reqwest::Client,
    // ...
}

@enriquein
Copy link
Author

I'm pretty new to Rust myself, and I have had issues trying to find the proper way to Clone something. Most of the documentation I find explains that "you need to figure out what cloning means for your type and how to correctly implement it". And while I completely understand the statement and why it works this way, I can't seem to find documentation on how to figure that out.

While I still think that this would increase the usability of this crate, please don't feel any pressure from my part to implement this feature. The project we were working on that used Rust has been cancelled and we're moving on to a different project that doesn't use Rust.

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

No branches or pull requests

2 participants