Skip to content

Replace lazy_static with std::sync::OnceLock - #301

Merged
jxs merged 2 commits into
rust-db:mainfrom
serprex:once-cell
Dec 29, 2023
Merged

jxs merged 2 commits into
rust-db:mainfrom
serprex:once-cell

Conversation

@serprex

@serprex serprex commented Dec 25, 2023

Copy link
Copy Markdown
Contributor

once_cell is preferred over lazy_static: rust-lang-nursery/lazy-static.rs#214

@jxs

jxs commented Dec 27, 2023

Copy link
Copy Markdown
Member

Hi, and thanks for this! I think we can even use OnceCell or OnceLock as they have been added to std and drop any external dependency for this, wdyt?

@serprex

serprex commented Dec 27, 2023

Copy link
Copy Markdown
Contributor Author

Given your MSRV policy, that works. It'll also be a much more impacting change, I'm thinking RE will be made private & a function will return reference to shared regex. In the case of runner.rs that's already almost done with file_match_re

@serprex

serprex commented Dec 27, 2023 •

Copy link
Copy Markdown
Contributor Author

Reading more closely, one of the REs were unused. For finding migration files there's now a match to decide whether to construct regex for rs or sql|rs. I imagine this isn't a case where constructing regex needs to be optimized so much, otherwise the two regexen could have their own OnceLock which the match would select & no format would be involved

@serprex serprex changed the title Replace lazy_static with once_cell Replace lazy_static with std::sync::OnceLock Dec 27, 2023

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! ❤️

@jxs
jxs merged commit 3a4a22b into rust-db:main Dec 29, 2023
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.

2 participants