-
-
Notifications
You must be signed in to change notification settings - Fork 411
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 a new type Convert<> to convert values #3786
Conversation
This can be used to transform values in to coerced versions by using the type system and TryFromJs.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3786 +/- ##
==========================================
+ Coverage 47.24% 50.19% +2.95%
==========================================
Files 476 457 -19
Lines 46892 44851 -2041
==========================================
+ Hits 22154 22513 +359
+ Misses 24738 22338 -2400 ☔ View full report in Codecov by Sentry. |
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 think this shouldn't be called Coerce
, since it's not really an implicit conversion. Instead, it should be called Cast<T>
, which makes sense as a name for an explicit conversion.
WDYT? |
Yeah, |
@jedel1043 ping for this. This is ready to review. |
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.
Looks great! Just a small nitpick that doesn't block merging.
I was thinking maybe we should add this logic to the let int = i32::try_from_js(&JsValue::from(10), context)?; Is there any benefit to having a separate struct? |
The problem is that I tend towards not doing that because I don't really like to have implicit conversions in Rust APIs, but we could discuss with the team if this is a behaviour we want from |
This can be used to transform values in to converted versions of Rust types by using the type system and
TryFromJs
.Also added a JsString conversion for
TryFromJs
. These methods are going to be useful when #3773 goes in (but this PR nor that one depend on each others).