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

Impl ImplicitClone for arrays and ref arrays #42

Merged
merged 12 commits into from
Nov 9, 2023
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
mod test {
use super::*;

fn host_library<T: ImplicitClone>(value: &T) -> T {
Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Collaborator

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

Copy link
Member Author

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 🤦‍♀️

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Collaborator

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

Copy link
Member Author

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 :(

Copy link
Member Author

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.)

fn host_library<T: ImplicitClone + Copy>(value: &T) -> T {
value.clone()

Check failure on line 142 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, 1.9.3)

using `clone` on type `T` which implements the `Copy` trait
}

macro_rules! host_library {
Expand All @@ -152,7 +152,7 @@

#[test]
fn custom() {
#[derive(Clone)]
#[derive(Clone, Copy)]
struct ImplicitCloneType;

impl ImplicitClone for ImplicitCloneType {}
Expand Down
Loading