-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - add Res::clone
#4109
Conversation
Would this prevent the contained data from being cloned by deref? let my_cloned_data = res.clone(); Like, would we need to do the alternate form: let my_cloned_data = (*res).clone(); |
the alternative form i think is actually |
Not a fan of this change. The expected behavior of a resource that is clonable should give you a cloned version of the inner value. If we explicitly want to create a new Does calling |
Same here
Indeed, this is what |
Actually both |
|
@@ -220,6 +220,17 @@ where | |||
} | |||
|
|||
impl<'w, T: Resource> Res<'w, T> { | |||
// no it shouldn't clippy | |||
#[allow(clippy::should_implement_trait)] | |||
pub fn clone(this: &Self) -> Self { |
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.
This should probably be #[inline]
as a tiny method.
After reading the discussion, I think I prefer the current design over implementing the trait. |
@@ -252,6 +252,17 @@ where | |||
} | |||
|
|||
impl<'w, T: Resource> Res<'w, T> { |
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.
Just throwing an idea out there: maybe we should call this something else to avoid the ambiguity entirely?
(ex: duplicate()
)
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.
Yep, that's my preference here too.
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.
Hmm actually within the context of requiring Res::clone
to resolve the ambiguity, I think thats nice and clear, given that we're cloning the Res. I think we should merge this as-is.
bors r+ |
Pull request successfully merged into main. Build succeeded: |
# Objective Make `Res` cloneable ## Solution Add an associated fn `clone(self: &Self) -. Self` instead of `Copy + Clone` trait impls to avoid `res.clone()` failing to clone out the underlying `T`
# Objective Make `Res` cloneable ## Solution Add an associated fn `clone(self: &Self) -. Self` instead of `Copy + Clone` trait impls to avoid `res.clone()` failing to clone out the underlying `T`
# Objective Make `Res` cloneable ## Solution Add an associated fn `clone(self: &Self) -. Self` instead of `Copy + Clone` trait impls to avoid `res.clone()` failing to clone out the underlying `T`
Objective
Make
Res
cloneableSolution
Add an associated fn
clone(self: &Self) -. Self
instead ofCopy + Clone
trait impls to avoidres.clone()
failing to clone out the underlyingT