-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Impl ImplicitClone for arrays and ref arrays #42
Conversation
I don't think this clone should be implicit. |
Yeah but
It does compile. |
Tip for this example lol, look at |
src/lib.rs
Outdated
@@ -138,7 +138,7 @@ macro_rules! imap_deconstruct { | |||
mod test { | |||
use super::*; | |||
|
|||
fn host_library<T: ImplicitClone>(value: &T) -> 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.
why? the point of the test wasn't just testing, it was an example of the "host library" term used in documentation
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.
well if it's in test, the point is to test, and right now I need the test to show to the developer I am actually adding impls on types that are actually Copy
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.
oh wait, the function is called "host_library" hahaha you're right
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.
well if it's in test, the point is to test
wrong, the point of a test is to document code in a way that has stronger guarantees (always actual info) than a comment or some sort of a separate wiki
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 fixed it but you won't like it xD if you want doc you put it in doc though. I think that makes more sense. Who's gonna check the crate's test to see how a crate is used anyway 🤦♀️
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.
If its possible, find a spot where to show to the user that they don't get implicit cloning in their code unless they make a host library (a macro)
I'm trying to find an example but the only thing I can think of is Yew's html itself. Maybe I can write an example with a simplified html!
macro. what do you think?
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.
wrong, the point of a test is to document code in a way that has stronger guarantees (always actual info) than a comment or some sort of a separate wiki
I mean the word itself is "test", at no point it's mentioning "document code". It's a single word and it's basic meaning is to test. It's true that I also sometimes consult the tests of a library to see how to use it but that's more because the thing is poorly documented. That never happened to me with crates in Rust, I never read Yew's tests to understand how to use the thing.
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.
all you need to show is that you no longer require clones
let a = SomeImmovableType;
host_library(a);
host_library(a); // fails, previous line moved the value
host_library!(a);
host_library!(a); // works, previous line cloned implicitly
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.
Maybe I should go with something simpler like you show here. My example isn't super good :(
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.
As you can see here and here it seems that people are still not understanding the point this crate despite our efforts to clarify it in #28.
What's interesting here is that you are right, people are definitely looking at the tests to see how it works! Though, I'm still in favor of providing a better and more sensical example within the documentation directly (crate doc + README).
Besides, I still would like the test to assert that we don't implement ImplicitClone on types that are not Copy.
(@kirillsemyonkin please bear with me as I really want to get to the bottom of this. As long as people are opening issues because they misunderstand or don't see how to use the crate, it means that there is work to do there and we should try our best to clarify things out.)
good to know! I checked but it's on nightly at the moment... so I'll keep the small function for now I guess |
src/lib.rs
Outdated
@@ -213,7 +213,6 @@ mod test { | |||
#[test] | |||
fn option() { | |||
assert_implicit_clone!(Some("foo")); | |||
// `assert_implicit_clone!(Some(NonImplicitCloneType));` doesn't compile |
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.
-fail
test would cover this lol
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.
what do you mean? I don't understand
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.
if there were -fail tests like for macros, then this "doesn't compile" example would be put there
I didn't want to push changes we don't all agree on so I reverted the changes on the tests and documentation and make a separate PR for those so we can merge already the small change of this PR which is adding arrays to the ImplicitClone family. @hamza1311 are you okay with the argument provided for implementing ImplicitClone on arrays? |
Yeah, I understand that argument. Feel free to merge it when you want to |
Related to yewstack/yew-autoprops#10