Skip to content

Add #[derive(Clone, Debug)] to all web-sys types #853

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
merged 1 commit into from
Sep 19, 2018

Conversation

alexcrichton
Copy link
Contributor

They're all cloneable and debuggable!

They're all cloneable and debuggable!
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@chinedufn
Copy link
Contributor

chinedufn commented Sep 19, 2018

Something that comes to mind here:

let mut elem = document.get_element_by_id("id");
let mut elem2 = elem1.clone();

One might expect that elem2 and elem1 each own their own copy of the underling #id element here, but that wouldn't be the case.

Mutating elem1 would mutate elem2.

Should you even be allowed to clone, what's the use case here (haven't thought through the cases here so I'm actually just asking ha)?

If so... should there instead be a let elem2 = web_sys::clone(elem1) to make this more clear?

@fitzgen
Copy link
Member

fitzgen commented Sep 19, 2018

@chinedufn it's the same as something like Rc<RefCell<...>>: shared ownership with interior mutability. If you think about it, JS things are always shared with JS land, and JS is not bound by the mutability xor aliasing that Rust usually follows, so everything in JS is implicitly mutable. Given that, I think it makes sense.

@fitzgen fitzgen merged commit e9212cf into rustwasm:master Sep 19, 2018
@chinedufn
Copy link
Contributor

Makes sense!

@alexcrichton alexcrichton deleted the clone branch September 21, 2018 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants