-
Notifications
You must be signed in to change notification settings - Fork 27
Add CloneGetters
#112
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
base: main
Are you sure you want to change the base?
Add CloneGetters
#112
Conversation
Thanks for the submission! If you're okay with not currently supporting |
This is not the case. You can clone an arc by invoking let arc: Arc<str> = Arc::from("hi");
// one way to clone it
let clone_1: Arc<str> = Arc::clone(&arc);
// since `Arc::clone` comes from the `Clone` trait this is the same as above
let clone_2: Arc<str> = Clone::clone(&arc);
// using the clone trait againt, but with method syntax
let clone_3: Arc<str> = arc.clone(); The above code (playground) compiles without a problem. Furthermore, the |
Correction: the |
This may have been a change since the last time I looked at it. As I recall, the documentation used to specifically call out |
Great, will do. |
From https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#cloning-references // The two syntaxes below are equivalent.
let a = foo.clone();
let b = Arc::clone(&foo); What yinz were probably thinking of is the methods that use You may have been thinking of this clippy lint, which suggests using the associated function syntax, so that things are more clear: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr Or, in the way olden days before 1.0, this may have been the case for a bit as well, I can't quite remember myself, but I did have to double check stuff here to post this comment! |
Thanks for clearing that up @steveklabnik! I think we can proceed with your solution @SLUCHABLUB. There is a possibility that I'm basing my recommendation off of pre-1.0 Rust, but regardless, I see from the documentation that this is not a limitation and it likely hasn't been for a while. Given that |
🎉 A big thanks to @jbaublitz, @SLUCHABLUB, and all contributors! 🎉 This feature caught my eye for a project recently and I tried out @SLUCHABLUB's branch. I can confirm it worked as expected. Here is a small sample how we used it. #[derive(Debug, Clone, Default, CloneGetters)]
#[getset(get_clone)]
pub struct PodJob {
pub pod: Arc<Pod>,
} Additionally, our project required attaching additional attributes to the generated |
Sorry it took so long, the tests are now updated. |
@SLUCHABLUB Can you take a look at CI? It looks like it's failing in a few places. |
I had forgot to run The actual error message is: |
@SLUCHABLUB I noticed the same. Working on fixing it in #115. Once I merge that, I'm going to ask you to rebase and squash the format commit. My guess is PR review will not take long. I will try to get out a release after I merge this as soon as possible, possibly even today if the turnaround for review is quick enough. |
#115 passed and is merged. Please rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just need to queue up a PR to update the documentation and then I'll merge.
I copied the code for
CopyGetters
, changing copy to clone. I have not written any additional documentation.closes #111