Skip to content

Make library more usable in a const context#203

Merged
alice-i-cecile merged 9 commits intoDioxusLabs:mainfrom
alice-i-cecile:all-the-consts
Jul 25, 2022
Merged

Make library more usable in a const context#203
alice-i-cecile merged 9 commits intoDioxusLabs:mainfrom
alice-i-cecile:all-the-consts

Conversation

@alice-i-cecile
Copy link
Copy Markdown
Collaborator

@alice-i-cecile alice-i-cecile commented Jul 22, 2022

Objective

When working with Style in Bevy, I noticed that a common pattern was to use ..Default::default() on what is now FlexboxLayout.

However, trait methods can't be constant in Rust (yet), so this can't be used to define new constant layout styles.

Changes:

  1. Add FlexboxLayout::DEFAULT.
  2. Clean up uses of constants.
  3. Make builder patterns constant where possible.

Context

Upstream tracking issue for the Rustl limitation: rust-lang/rust#63065.

Some builder methods could not be made const because of orlp/slotmap#85.

@alice-i-cecile alice-i-cecile added usability Make the library more comfortable to use code quality Make the code cleaner or prettier. labels Jul 22, 2022
@alice-i-cecile
Copy link
Copy Markdown
Collaborator Author

Going to leave this up for a couple days; changes are trivial but if you see this feel free to review.

@alice-i-cecile alice-i-cecile enabled auto-merge (squash) July 25, 2022 20:03
@alice-i-cecile alice-i-cecile merged commit 034f064 into DioxusLabs:main Jul 25, 2022
jkelleyrtp pushed a commit that referenced this pull request Oct 10, 2022
* Add FlexboxLayout::DEFAULT constant

* Make constructors const where possible

* Use Size::NONE instead of Size::undefined()

* Stick with Layout::new

* More advice on setting up chromedriver

* More const builders

* Update tests

* Fix find-and-replace error in CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Make the code cleaner or prettier. usability Make the library more comfortable to use

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants