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

Add JsString <-> char conversions #1473

Merged
merged 2 commits into from
Apr 24, 2019
Merged

Conversation

RReverser
Copy link
Member

These are pretty common and already supported via ABI conversions, yet pretty easy to get wrong when converting them manually.

Fixes #1363.

@alexcrichton
Copy link
Contributor

Seems reasonable to me, thanks @RReverser! Just to confirm with a second opinion, @Pauan mind checking as well?

Copy link
Contributor

@Pauan Pauan left a comment

Choose a reason for hiding this comment

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

Looks mostly good, just a couple things need to be fixed.

crates/js-sys/src/lib.rs Show resolved Hide resolved
crates/js-sys/src/lib.rs Outdated Show resolved Hide resolved
crates/js-sys/src/lib.rs Outdated Show resolved Hide resolved
crates/js-sys/src/lib.rs Show resolved Hide resolved
crates/js-sys/src/lib.rs Outdated Show resolved Hide resolved
crates/js-sys/src/lib.rs Show resolved Hide resolved
crates/js-sys/tests/wasm/JsString.rs Show resolved Hide resolved
@RReverser
Copy link
Member Author

@Pauan All your other suggestions make sense to me.

Any chance you could submit them using "Github suggestion" comments which I could easily accept (including from the phone)?

Otherwise I won't get around to this until after the Easter holiday (later next week).

@RReverser RReverser force-pushed the chars branch 2 times, most recently from 7f78a25 to 91f112d Compare April 23, 2019 14:52
These are pretty common and already supported via ABI conversions, yet pretty easy to get wrong when converting them manually.

Fixes rustwasm#1363.
@RReverser
Copy link
Member Author

Ok fixed most nits (except the PartialEq thing, which I still think is useful in this context).

@alexcrichton
Copy link
Contributor

I think I would agree with @Pauan here actually, could the From be removed as well as the PartialEq? They're compatible to add later but currently inconsistent with Rust's libstd

@RReverser
Copy link
Member Author

Hmm, From is actually half of the PR... I don't think comparing with libstd makes sense, as it doesn't have string -> char conversion either, because, again, it has a separate type to represent it.

@Pauan
Copy link
Contributor

Pauan commented Apr 23, 2019

Sorry for the delay, I recently caught a nasty cold.

I'm a bit wary of PartialEq, but I'm not strongly against it.

I feel like From is quite reasonable, so most of my concerns are with PartialEq.

I think they do seem rather useful, since JS itself doesn't make a distinction between strings and chars.

But I'm also okay with deferring them to a future PR.

@RReverser
Copy link
Member Author

Sorry for the delay, I recently caught a nasty cold.

No worries and get well!

This seems to spark controversy, so removing for now but should be easy enough to still add in the future.
@RReverser
Copy link
Member Author

Alright, I removed PartialEq<char> for now to avoid controversy around the PR and, indeed, we can still add it in the future.

@alexcrichton alexcrichton merged commit cc89109 into rustwasm:master Apr 24, 2019
@alexcrichton
Copy link
Contributor

Thanks @RReverser!

@RReverser RReverser deleted the chars branch April 24, 2019 19:14
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.

Consider adding JsValue::as_char
3 participants