-
Notifications
You must be signed in to change notification settings - Fork 23
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
Make unbounded a const function #67
Conversation
src/unbounded.rs
Outdated
@@ -149,6 +149,22 @@ pub struct Unbounded<T> { | |||
|
|||
impl<T> Unbounded<T> { | |||
/// Creates a new unbounded queue. | |||
#[cfg(not(loom))] |
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.
this sort of code duplication is very unfortunate, could we encapsulate that into a macro? (just the cfg + const switch)
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.
(Feel free to copy a helper macro used in my crates if needed)
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.
Done.
Co-authored-by: Taiki Endo <[email protected]>
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.
Thanks!
This PR makes
ConcurrentQueue::unbounded
a const function. It'd be great ifbounded
could beconst
as well, but this would likely require static memory allocation support in const functions, which is currently not allowed by the compiler. This would enable smol-rs/async-executor#112 to be directly constructable in a const context (i.e. static/thread_local variable initialization without OnceLock). It might also allow unboundedasync_channel
s to be constructed in a similar context.