-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Remove once_cell dependency #3520
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 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
361baf9
Remove once_cell dependency
james7132 702bd12
Fix typo
james7132 4154614
Formatting
james7132 fadef45
Remove Lazy::get, only Deref is used.
james7132 9a1085c
Constrict the unsafe impl to match once_cell's
james7132 19ae9f7
Make Lazy statics pub(crate).
james7132 aa3a0d6
Make more of the pub Lazy statics pub(crate)
james7132 a95f1dd
Mutex instead of Cell
james7132 bed0033
Don't allow closures
james7132 66fcd6c
Merge branch 'master' into remove-once-cell
james7132 a4ebaea
Allow dead code for Lazy
james7132 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
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 |
|---|---|---|
|
|
@@ -187,6 +187,7 @@ mod icon; | |
| pub mod keyboard; | ||
| pub mod monitor; | ||
| mod platform_impl; | ||
| mod utils; | ||
| pub mod window; | ||
|
|
||
| pub mod platform; | ||
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
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
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
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
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use std::sync::Mutex; | ||
|
|
||
| use once_cell::sync::Lazy; | ||
| use crate::utils::Lazy; | ||
|
|
||
| use super::*; | ||
|
|
||
|
|
||
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
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
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
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
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
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,33 @@ | ||
| // A poly-fill for `lazy_cell` | ||
| // Replace with std::sync::LazyLock when https://github.com/rust-lang/rust/issues/109736 is stablized. | ||
|
|
||
| use std::cell::Cell; | ||
| use std::ops::Deref; | ||
| use std::sync::OnceLock; | ||
|
|
||
| pub(crate) struct Lazy<T, F = fn() -> T> { | ||
| cell: OnceLock<T>, | ||
| init: Cell<Option<F>>, | ||
| } | ||
|
|
||
| unsafe impl<T, F> Sync for Lazy<T, F> {} | ||
|
|
||
| impl<T, F: FnOnce() -> T> Lazy<T, F> { | ||
| pub const fn new(f: F) -> Self { | ||
| Self { | ||
| cell: OnceLock::new(), | ||
| init: Cell::new(Some(f)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | ||
| type Target = T; | ||
| #[inline] | ||
| fn deref(&self) -> &'_ T { | ||
| self.cell.get_or_init(|| match self.init.take() { | ||
| Some(f) => f(), | ||
| None => unreachable!(), | ||
| }) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.