Skip to content

Commit 9cb5985

Browse files
authored
Merge pull request #402 from eval-exec/exec/upgrade-rust-2024
Rust Toolchain: Upgrade to rust edition 2024
2 parents f685607 + f51ff41 commit 9cb5985

File tree

98 files changed

+344
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+344
-353
lines changed

bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "bench"
33
version = "0.1.0"
44
authors = ["piaoliu <441594700@qq.com>"]
5-
edition = "2021"
5+
edition = "2024"
66

77
[lib]
88
name = "bench"

bench/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Bench {
6868
self.cycles,
6969
total,
7070
total / self.cycles,
71-
self.executed_time_list[(self.cycles/2) as usize],
71+
self.executed_time_list[(self.cycles / 2) as usize],
7272
self.executed_time_list[self.cycles as usize - 1],
7373
self.executed_time_list[0]
7474
)

bench/src/main.rs

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bench::Bench;
22
use bytes::Bytes;
33
use futures::channel;
44
use p2p::{
5-
async_trait,
5+
ProtocolId, async_trait,
66
builder::{MetaBuilder, ServiceBuilder},
77
context::{ProtocolContext, ProtocolContextMutRef},
88
multiaddr::Multiaddr,
@@ -11,19 +11,21 @@ use p2p::{
1111
ProtocolHandle, ProtocolMeta, Service, ServiceControl, TargetProtocol, TargetSession,
1212
},
1313
traits::{ServiceHandle, ServiceProtocol},
14-
ProtocolId,
1514
};
16-
use std::{sync::Once, thread};
15+
use std::{
16+
sync::{Once, OnceLock},
17+
thread,
18+
};
1719
use tokio_util::codec::length_delimited::Builder;
1820

1921
static START_SECIO: Once = Once::new();
2022
static START_NO_SECIO: Once = Once::new();
2123

22-
static mut SECIO_CONTROL: Option<ServiceControl> = None;
23-
static mut NO_SECIO_CONTROL: Option<ServiceControl> = None;
24+
static SECIO_CONTROL: OnceLock<ServiceControl> = OnceLock::new();
25+
static NO_SECIO_CONTROL: OnceLock<ServiceControl> = OnceLock::new();
2426

25-
static mut SECIO_RECV: Option<crossbeam_channel::Receiver<Notify>> = None;
26-
static mut NO_SECIO_RECV: Option<crossbeam_channel::Receiver<Notify>> = None;
27+
static SECIO_RECV: OnceLock<crossbeam_channel::Receiver<Notify>> = OnceLock::new();
28+
static NO_SECIO_RECV: OnceLock<crossbeam_channel::Receiver<Notify>> = OnceLock::new();
2729

2830
#[derive(Debug, PartialEq)]
2931
enum Notify {
@@ -134,10 +136,8 @@ pub fn init() {
134136
});
135137

136138
assert_eq!(client_receiver.recv(), Ok(Notify::Connected));
137-
unsafe {
138-
SECIO_CONTROL = Some(control.into());
139-
SECIO_RECV = Some(client_receiver);
140-
}
139+
assert!(SECIO_CONTROL.set(control.into()).is_ok());
140+
assert!(SECIO_RECV.set(client_receiver).is_ok());
141141
});
142142

143143
// init no secio two peers
@@ -174,43 +174,37 @@ pub fn init() {
174174
});
175175

176176
assert_eq!(client_receiver.recv(), Ok(Notify::Connected));
177-
unsafe {
178-
NO_SECIO_CONTROL = Some(control.into());
179-
NO_SECIO_RECV = Some(client_receiver);
180-
}
177+
assert!(NO_SECIO_CONTROL.set(control.into()).is_ok());
178+
assert!(NO_SECIO_RECV.set(client_receiver).is_ok());
181179
});
182180
}
183181

184182
fn secio_and_send_data(data: &[u8]) {
185-
unsafe {
186-
SECIO_CONTROL.as_mut().map(|control| {
187-
control.filter_broadcast(
188-
TargetSession::All,
189-
ProtocolId::new(1),
190-
Bytes::from(data.to_owned()),
191-
)
192-
});
193-
if let Some(rev) = SECIO_RECV.as_ref() {
194-
assert_eq!(
195-
rev.recv(),
196-
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
197-
)
198-
}
183+
SECIO_CONTROL.get().map(|control| {
184+
control.filter_broadcast(
185+
TargetSession::All,
186+
ProtocolId::new(1),
187+
Bytes::from(data.to_owned()),
188+
)
189+
});
190+
if let Some(rev) = SECIO_RECV.get() {
191+
assert_eq!(
192+
rev.recv(),
193+
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
194+
)
199195
}
200196
}
201197

202198
fn no_secio_and_send_data(data: &[u8]) {
203-
unsafe {
204-
NO_SECIO_CONTROL.as_mut().map(|control| {
205-
control.filter_broadcast(TargetSession::All, 1.into(), Bytes::from(data.to_owned()))
206-
});
199+
NO_SECIO_CONTROL.get().map(|control| {
200+
control.filter_broadcast(TargetSession::All, 1.into(), Bytes::from(data.to_owned()))
201+
});
207202

208-
if let Some(rev) = NO_SECIO_RECV.as_ref() {
209-
assert_eq!(
210-
rev.recv(),
211-
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
212-
)
213-
}
203+
if let Some(rev) = NO_SECIO_RECV.get() {
204+
assert_eq!(
205+
rev.recv(),
206+
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
207+
)
214208
}
215209
}
216210

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "tentacle-fuzz"
33
version = "0.0.1"
44
license = "MIT"
55
authors = ["Nervos Core Dev <dev@nervos.org>"]
6-
edition = "2021"
6+
edition = "2024"
77

88
[package.metadata]
99
cargo-fuzz = true

multiaddr/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name = "tentacle-multiaddr"
33
version = "0.3.5"
44
authors = ["driftluo <driftluo@foxmail.com>"]
5-
edition = "2021"
6-
rust-version = "1.61.0"
5+
edition = "2024"
6+
rust-version = "1.85.0"
77
repository = "https://github.com/nervosnetwork/tentacle"
88
license = "MIT"
99
description = "Mini Implementation of multiaddr"

multiaddr/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
1+
//! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
22
mod error;
33
mod onion_addr;
44
mod protocol;
@@ -8,8 +8,8 @@ pub use self::onion_addr::Onion3Addr;
88
pub use self::protocol::Protocol;
99
use bytes::{Bytes, BytesMut};
1010
use serde::{
11-
de::{self, Error as DeserializerError},
1211
Deserialize, Deserializer, Serialize, Serializer,
12+
de::{self, Error as DeserializerError},
1313
};
1414
use std::{
1515
fmt,

multiaddr/src/onion_addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{borrow::Cow, fmt};
44
#[derive(Clone)]
55
pub struct Onion3Addr<'a>(Cow<'a, [u8; 35]>, u16);
66

7-
impl<'a> Onion3Addr<'a> {
7+
impl Onion3Addr<'_> {
88
/// Return the hash of the public key as bytes
99
pub fn hash(&self) -> &[u8; 35] {
1010
self.0.as_ref()

multiaddr/src/protocol.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
str::{self, FromStr},
1111
};
1212

13-
use crate::{error::Error, Onion3Addr};
13+
use crate::{Onion3Addr, error::Error};
1414

1515
const DNS4: u32 = 0x36;
1616
const DNS6: u32 = 0x37;
@@ -258,7 +258,7 @@ impl<'a> Protocol<'a> {
258258
}
259259
}
260260

261-
impl<'a> fmt::Display for Protocol<'a> {
261+
impl fmt::Display for Protocol<'_> {
262262
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263263
use self::Protocol::*;
264264
match self {
@@ -280,7 +280,7 @@ impl<'a> fmt::Display for Protocol<'a> {
280280
}
281281
}
282282

283-
impl<'a> From<IpAddr> for Protocol<'a> {
283+
impl From<IpAddr> for Protocol<'_> {
284284
#[inline]
285285
fn from(addr: IpAddr) -> Self {
286286
match addr {
@@ -290,14 +290,14 @@ impl<'a> From<IpAddr> for Protocol<'a> {
290290
}
291291
}
292292

293-
impl<'a> From<Ipv4Addr> for Protocol<'a> {
293+
impl From<Ipv4Addr> for Protocol<'_> {
294294
#[inline]
295295
fn from(addr: Ipv4Addr) -> Self {
296296
Protocol::Ip4(addr)
297297
}
298298
}
299299

300-
impl<'a> From<Ipv6Addr> for Protocol<'a> {
300+
impl From<Ipv6Addr> for Protocol<'_> {
301301
#[inline]
302302
fn from(addr: Ipv6Addr) -> Self {
303303
Protocol::Ip6(addr)

protocols/discovery/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "p2p discovery protocol main reference bitcoin"
77
keywords = ["network", "peer-to-peer", "p2p", "discovery"]
88
repository = "https://github.com/nervosnetwork/tentacle"
99
categories = ["network-programming", "asynchronous"]
10-
edition = "2018"
10+
edition = "2024"
1111

1212
[package.metadata.docs.rs]
1313
features = []

protocols/identify/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "p2p identify protocol"
77
keywords = ["network", "peer-to-peer", "p2p", "identify"]
88
repository = "https://github.com/nervosnetwork/tentacle"
99
categories = ["network-programming", "asynchronous"]
10-
edition = "2018"
10+
edition = "2024"
1111

1212
[package.metadata.docs.rs]
1313
features = []

0 commit comments

Comments
 (0)