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 |
|
|
| 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.
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.
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.
Yep, that's my preference here too.
There was a problem hiding this comment.
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
RescloneableSolution
Add an associated fn
clone(self: &Self) -. Selfinstead ofCopy + Clonetrait impls to avoidres.clone()failing to clone out the underlyingT