Skip to content

Commit

Permalink
Work well with older lock_api versions
Browse files Browse the repository at this point in the history
The crate `lock_api` is a transitive dependency, pulled in trough the
use of `parking_lot`. `parking_lot` depends on `lock_api` version
`^0.4.6`, but only since `lock_api` 0.4.7 the `RwLock::new()` method is
available on rust stable, coinciding with the release of rust
[1.61][const_fn_trait_bound].

A problem occurs if you try to use `once_map` with non-up-to-date
dependencies, e.g. by running

```sh
RUSTC_BOOTSTRAP=1 cargo generate-lockfile -Zminimal-versions
```

This PR makes `Shard::new()` non-`const`, so it works with older
`lock_api` versions, too.
  • Loading branch information
Kijewski authored and a1phyr committed Aug 28, 2024
1 parent b9ca977 commit 37dc475
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct Shard<K, V> {
}

impl<K, V> Shard<K, V> {
const fn new() -> Self {
fn new() -> Self {
Self {
map: RwLock::new(HashMap::new()),
waiters: Mutex::new(HashMap::new()),
Expand Down

0 comments on commit 37dc475

Please sign in to comment.