-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add constructor functions for each variant of Val
#20518
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f1b9678
Add constructor functions for each variant of Val
ickshonpe 694b926
Edit comment
ickshonpe 331965e
Merge branch 'main' into val-variant-constructors
ickshonpe ebc8979
Add a release note.
ickshonpe 8a1eab5
Merge branch 'val-variant-constructors' of https://github.com/ickshon…
ickshonpe 52b8f8b
fixed formatting
ickshonpe 145ecc9
Fix release note formatting.
ickshonpe f5d5d81
Merge branch 'main' into val-variant-constructors
ickshonpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
release-content/release-notes/constructor_functions_for_val_variants.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: `Val` helper functions | ||
authors: ["@Ickshonpe"] | ||
pull_requests: [20518] | ||
--- | ||
|
||
To make `Val`s easier to construct the following helper functions have been added: `px`, `percent`, `vw`, `vh`, `vmin` and `vmax`. Each function takes an `f32` value and returns value wrapped by its corresponding `Val` variant. There is also an `auto` helper function that maps to `Val::Auto`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The alternative to this is adding
use Val::*
to the prelude, which feels less "special" to me, ties the docs directly toVal
, keeps our code size down, and aligns with Rust std patterns (ex:Some
,None
,Ok
,Err
, etc).The only problem is right now
bsn!
breaks on this case (as it assumes it can doparent_type.value.0
to setSome(x)
). This is obviously a problem! The solution is to useif let
to destructure all types. I believe this will also solve one of the outstanding autocomplete issues (and it will remove the need for thetouch_type
hack).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'm going to strongly advocate that we do
use Val::*
instead.Uh oh!
There was an error while loading. Please reload this page.
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 it just comes down to whether we wanna allow more types besides just
f32
or not #20518 (comment).But I think a decision needs to be made and you're the one to do it. I personally like the idea of being able to omit the decimal seperator, especially because this PR is about code readability, but it is ultimately up to you.
I just think, it would be nice to ship this in 0.17 (although it isn't important enough to be blocking, as @alice-i-cecile said on discord)
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.
Arg yeah that does make this comfier. And currently type inference actually doesn't break in
bsn!
right now, as function arguments don't have implicitinto()
.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.
Arguably less rusty, and it means we're encouraging people to throw a bunch of "int to float" casts everywhere. But I'll admit to hitting the "oops please make it a float" friction on the regular.
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.
It does also mean we'll likely need to special case these functions somehow in BSN asset files (if we want to support them there). But I'm content making that a problem for future us.
Consider this approval for function helpers with type conversion.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry to bother you one more time, but now I'm a bit confused: what do you actually mean by this? That we might add automatic type conversion in a later PR or that it will be done by BSN?
But thanks for finally merging this, this will already make things way easier than before!
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.
It will be done by BSN. There's automatic
.into()
calls via the macro now.Uh oh!
There was an error while loading. Please reload this page.
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.
@alice-i-cecile thats not what I meant in this case (see my message above about function parameters not having implicit into). Instead, we should add a trait as mentioned elsewhere.