Skip to content

Commit de9274e

Browse files
authored
futures-util: make Mutex::new() const (#2956)
This builds with the MSRV (1.68) and is convenient for creating `static` mutexes. This does bind the implementation to never allocate in `new` in the future, but that seems like a desirable property anyway. Note that this also requires updating slab to 0.4.7, which is the first version that supports const `Slab::new()`.
1 parent b95f0ad commit de9274e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

futures-util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ futures-channel = { path = "../futures-channel", version = "=0.4.0-alpha.0", def
3737
futures-io = { path = "../futures-io", version = "0.3.31", default-features = false, features = ["std"], optional = true }
3838
futures-sink = { path = "../futures-sink", version = "=0.4.0-alpha.0", default-features = false, optional = true }
3939
futures-macro = { path = "../futures-macro", version = "=0.4.0-alpha.0", default-features = false, optional = true }
40-
slab = { version = "0.4.2", default-features = false, optional = true }
40+
slab = { version = "0.4.7", default-features = false, optional = true }
4141
memchr = { version = "2.2", optional = true }
4242
futures_01 = { version = "0.1.25", optional = true, package = "futures" }
4343
tokio-io = { version = "0.1.9", optional = true }

futures-util/src/lock/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const HAS_WAITERS: usize = 1 << 1;
7373

7474
impl<T> Mutex<T> {
7575
/// Creates a new futures-aware mutex.
76-
pub fn new(t: T) -> Self {
76+
pub const fn new(t: T) -> Self {
7777
Self {
7878
state: AtomicUsize::new(0),
7979
waiters: StdMutex::new(Slab::new()),

0 commit comments

Comments
 (0)