Skip to content

Commit b685b63

Browse files
authored
refactor: replace the once_cell dependency with std equivalents
Pull-Request: #5913.
1 parent e99ab75 commit b685b63

File tree

16 files changed

+48
-40
lines changed

16 files changed

+48
-40
lines changed

Cargo.lock

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ libp2p = { version = "0.55.1", path = "libp2p" }
7878
libp2p-allow-block-list = { version = "0.5.0", path = "misc/allow-block-list" }
7979
libp2p-autonat = { version = "0.14.1", path = "protocols/autonat" }
8080
libp2p-connection-limits = { version = "0.5.1", path = "misc/connection-limits" }
81-
libp2p-core = { version = "0.43.0", path = "core" }
81+
libp2p-core = { version = "0.43.1", path = "core" }
8282
libp2p-dcutr = { version = "0.13.0", path = "protocols/dcutr" }
8383
libp2p-dns = { version = "0.43.0", path = "transports/dns" }
8484
libp2p-floodsub = { version = "0.46.1", path = "protocols/floodsub" }
@@ -90,7 +90,7 @@ libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" }
9090
libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" }
9191
libp2p-metrics = { version = "0.16.1", path = "misc/metrics" }
9292
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }
93-
libp2p-noise = { version = "0.46.0", path = "transports/noise" }
93+
libp2p-noise = { version = "0.46.1", path = "transports/noise" }
9494
libp2p-peer-store = { version = "0.1.0", path = "misc/peer-store" }
9595
libp2p-perf = { version = "0.4.0", path = "protocols/perf" }
9696
libp2p-ping = { version = "0.46.0", path = "protocols/ping" }
@@ -114,7 +114,7 @@ libp2p-webrtc-utils = { version = "0.4.0", path = "misc/webrtc-utils" }
114114
libp2p-webrtc-websys = { version = "0.4.0", path = "transports/webrtc-websys" }
115115
libp2p-websocket = { version = "0.45.1", path = "transports/websocket" }
116116
libp2p-websocket-websys = { version = "0.5.0", path = "transports/websocket-websys" }
117-
libp2p-webtransport-websys = { version = "0.5.0", path = "transports/webtransport-websys" }
117+
libp2p-webtransport-websys = { version = "0.5.1", path = "transports/webtransport-websys" }
118118
libp2p-yamux = { version = "0.47.0", path = "muxers/yamux" }
119119

120120
# External dependencies

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.43.1
2+
- Remove `once_cell` dependency.
3+
See [PR 5913](https://github.com/libp2p/rust-libp2p/pull/5913)
4+
15
## 0.43.0
26

37
- Added `libp2p::core::util::unreachable` that is a drop-in replacement of `void::unreachable`.

core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-core"
33
edition.workspace = true
44
rust-version = { workspace = true }
55
description = "Core traits and structs of libp2p"
6-
version = "0.43.0"
6+
version = "0.43.1"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"
@@ -20,7 +20,6 @@ libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] }
2020
multiaddr = { workspace = true }
2121
multihash = { workspace = true }
2222
multistream-select = { workspace = true }
23-
once_cell = "1.19.0"
2423
parking_lot = "0.12.3"
2524
pin-project = "1.1.5"
2625
quick-protobuf = "0.8"

core/src/transport/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::{
2323
error, fmt, io,
2424
num::NonZeroU64,
2525
pin::Pin,
26+
sync::LazyLock,
2627
};
2728

2829
use fnv::FnvHashMap;
@@ -33,13 +34,12 @@ use futures::{
3334
task::{Context, Poll},
3435
};
3536
use multiaddr::{Multiaddr, Protocol};
36-
use once_cell::sync::Lazy;
3737
use parking_lot::Mutex;
3838
use rw_stream_sink::RwStreamSink;
3939

4040
use crate::transport::{DialOpts, ListenerId, Transport, TransportError, TransportEvent};
4141

42-
static HUB: Lazy<Hub> = Lazy::new(|| Hub(Mutex::new(FnvHashMap::default())));
42+
static HUB: LazyLock<Hub> = LazyLock::new(|| Hub(Mutex::new(FnvHashMap::default())));
4343

4444
struct Hub(Mutex<FnvHashMap<NonZeroU64, ChannelSender>>);
4545

swarm/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## 0.47.0
2+
- Remove `once_cell` dependency.
3+
See [PR 5913](https://github.com/libp2p/rust-libp2p/pull/5913)
4+
25
- Separate the `PendingConnectionError` into two parts `PendingOutboundConnectionError` and `PendingInboundConnectionError` to have better control over error handling. See [PR](https://github.com/libp2p/rust-libp2p/pull/5861)
36

47
- Undo `ConnectionHandler::{InboundOpenInfo, OutboundOpenInfo}` deprecation.

swarm/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ libp2p-identity = { workspace = true }
2222
libp2p-swarm-derive = { workspace = true, optional = true }
2323
lru = "0.12.3"
2424
multistream-select = { workspace = true }
25-
once_cell = "1.19.0"
2625
rand = "0.8"
2726
smallvec = "1.13.2"
2827
tracing = { workspace = true }
@@ -52,7 +51,6 @@ libp2p-swarm-test = { path = "../swarm-test" } # Using `pat
5251
libp2p-yamux = { path = "../muxers/yamux" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing.
5352
quickcheck = { workspace = true }
5453
criterion = { version = "0.5", features = ["async_tokio"] }
55-
once_cell = "1.19.0"
5654
trybuild = "1.0.95"
5755
tokio = { workspace = true, features = ["time", "rt", "macros", "rt-multi-thread"] }
5856
tracing-subscriber = { workspace = true, features = ["env-filter"] }

swarm/src/behaviour/external_addresses.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ impl ExternalAddresses {
8787

8888
#[cfg(test)]
8989
mod tests {
90+
use std::sync::LazyLock;
91+
9092
use libp2p_core::multiaddr::Protocol;
91-
use once_cell::sync::Lazy;
9293
use rand::Rng;
9394

9495
use super::*;
@@ -179,8 +180,8 @@ mod tests {
179180
})
180181
}
181182

182-
static MEMORY_ADDR_1000: Lazy<Multiaddr> =
183-
Lazy::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
184-
static MEMORY_ADDR_2000: Lazy<Multiaddr> =
185-
Lazy::new(|| Multiaddr::empty().with(Protocol::Memory(2000)));
183+
static MEMORY_ADDR_1000: LazyLock<Multiaddr> =
184+
LazyLock::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
185+
static MEMORY_ADDR_2000: LazyLock<Multiaddr> =
186+
LazyLock::new(|| Multiaddr::empty().with(Protocol::Memory(2000)));
186187
}

swarm/src/behaviour/listen_addresses.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ impl ListenAddresses {
3535
#[cfg(test)]
3636
mod tests {
3737
use libp2p_core::{multiaddr::Protocol, transport::ListenerId};
38-
use once_cell::sync::Lazy;
3938

4039
use super::*;
4140

@@ -76,6 +75,6 @@ mod tests {
7675
})
7776
}
7877

79-
static MEMORY_ADDR: Lazy<Multiaddr> =
80-
Lazy::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
78+
static MEMORY_ADDR: std::sync::LazyLock<Multiaddr> =
79+
std::sync::LazyLock::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
8180
}

swarm/src/behaviour/peer_addresses.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ impl Default for PeerAddresses {
9595

9696
#[cfg(test)]
9797
mod tests {
98-
use std::io;
98+
use std::{io, sync::LazyLock};
9999

100100
use libp2p_core::{
101101
multiaddr::Protocol,
102102
transport::{memory::MemoryTransportError, TransportError},
103103
};
104-
use once_cell::sync::Lazy;
105104

106105
use super::*;
107106
use crate::ConnectionId;
@@ -328,8 +327,8 @@ mod tests {
328327
errors
329328
}
330329

331-
static MEMORY_ADDR_1000: Lazy<Multiaddr> =
332-
Lazy::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
333-
static MEMORY_ADDR_2000: Lazy<Multiaddr> =
334-
Lazy::new(|| Multiaddr::empty().with(Protocol::Memory(2000)));
330+
static MEMORY_ADDR_1000: LazyLock<Multiaddr> =
331+
LazyLock::new(|| Multiaddr::empty().with(Protocol::Memory(1000)));
332+
static MEMORY_ADDR_2000: LazyLock<Multiaddr> =
333+
LazyLock::new(|| Multiaddr::empty().with(Protocol::Memory(2000)));
335334
}

0 commit comments

Comments
 (0)