Skip to content

Commit

Permalink
refactor: move to rust edition 2024 (#1528)
Browse files Browse the repository at this point in the history
* refactor: move rust edition 2024

* cargo fmt

* enable lint for if let scope changes

* add workspace lints + edition2024 lint

* fix bad merge

* wasm tests: install latest rustc version
  • Loading branch information
niklasad1 authored Mar 10, 2025
1 parent 4b70c82 commit 9272591
Show file tree
Hide file tree
Showing 74 changed files with 197 additions and 176 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ jobs:

- uses: actions/[email protected]

- name: Install Rust 1.81.0 toolchain
- name: Install Rust 1.85.0 toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
# Check that jsonrpsee compiles with MSRV
toolchain: 1.81
toolchain: 1.85
override: true

- name: Rust Cache
Expand Down Expand Up @@ -200,6 +200,13 @@ jobs:
steps:
- uses: actions/[email protected]

- name: Install Rust stable toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
toolchain: stable
override: true

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Expand Down
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ members = [
"tests/proc-macro-core",
"types",
]
resolver = "2"
resolver = "3"

[workspace.package]
authors = ["Parity Technologies <[email protected]>", "Pierre Krieger <[email protected]>"]
version = "0.24.7"
edition = "2021"
rust-version = "1.81.0"
edition = "2024"
rust-version = "1.85.0"
license = "MIT"
repository = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee"
Expand Down Expand Up @@ -92,3 +92,9 @@ pprof = { version = "0.14", features = ["flamegraph", "criterion"] }
socket2 = "0.5.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
trybuild = "1.0.97"

[workspace.lints.rust]
rust_2024_compatibility = { level = "warn", priority = -1 }
missing_docs = { level = "warn", priority = -1 }
missing_debug_implementations = { level = "warn", priority = -1 }
missing_copy_implementations = { level = "warn", priority = -1 }
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::sync::Arc;
use std::time::Duration;

use criterion::*;
use futures_util::future::{join_all, FutureExt};
use futures_util::future::{FutureExt, join_all};
use futures_util::stream::FuturesUnordered;
use helpers::fixed_client::{
http_client, rpc_params, ws_client, ws_handshake, ArrayParams, BatchRequestBuilder, ClientT, HeaderMap,
SubscriptionClientT,
ArrayParams, BatchRequestBuilder, ClientT, HeaderMap, SubscriptionClientT, http_client, rpc_params, ws_client,
ws_handshake,
};
use helpers::{KIB, SUB_METHOD_NAME, UNSUB_METHOD_NAME};
use jsonrpsee::types::{Id, RequestSer};
Expand Down
3 changes: 3 additions & 0 deletions client/http-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords.workspace = true
readme.workspace = true
publish = true

[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
base64 = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion client/http-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use async_trait::async_trait;
use hyper::body::Bytes;
use hyper::http::HeaderMap;
use jsonrpsee_core::client::{
generate_batch_id_range, BatchResponse, ClientT, Error, IdKind, RequestIdManager, Subscription, SubscriptionClientT,
BatchResponse, ClientT, Error, IdKind, RequestIdManager, Subscription, SubscriptionClientT, generate_batch_id_range,
};
use jsonrpsee_core::params::BatchRequestBuilder;
use jsonrpsee_core::traits::ToRpcParams;
Expand Down
1 change: 0 additions & 1 deletion client/http-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
//! which is not compatible with other async runtimes such as
//! [`async-std`](https://docs.rs/async-std/), [`smol`](https://docs.rs/smol) and similar.
#![warn(missing_docs, missing_debug_implementations, missing_copy_implementations, unreachable_pub)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]

Expand Down
8 changes: 4 additions & 4 deletions client/http-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::types::error::{ErrorCode, ErrorObject};
use crate::HttpClientBuilder;
use crate::types::error::{ErrorCode, ErrorObject};
use jsonrpsee_core::ClientError;
use jsonrpsee_core::client::{BatchResponse, ClientT, IdKind};
use jsonrpsee_core::params::BatchRequestBuilder;
use jsonrpsee_core::ClientError;
use jsonrpsee_core::{rpc_params, DeserializeOwned};
use jsonrpsee_core::{DeserializeOwned, rpc_params};
use jsonrpsee_test_utils::TimeoutFutureExt;
use jsonrpsee_test_utils::helpers::*;
use jsonrpsee_test_utils::mocks::Id;
use jsonrpsee_test_utils::TimeoutFutureExt;
use jsonrpsee_types::error::ErrorObjectOwned;

fn init_logger() {
Expand Down
6 changes: 3 additions & 3 deletions client/http-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use base64::Engine;
use hyper::body::Bytes;
use hyper::http::{HeaderMap, HeaderValue};
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::rt::TokioExecutor;
use jsonrpsee_core::tracing::client::{rx_log_from_bytes, tx_log_from_str};
use jsonrpsee_core::BoxError;
use jsonrpsee_core::tracing::client::{rx_log_from_bytes, tx_log_from_str};
use jsonrpsee_core::{
http_helpers::{self, HttpError},
TEN_MB_SIZE_BYTES,
http_helpers::{self, HttpError},
};
use std::future::Future;
use std::pin::Pin;
Expand Down
3 changes: 3 additions & 0 deletions client/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords.workspace = true
readme.workspace = true
publish = true

[lints]
workspace = true

[dependencies]
jsonrpsee-core = { workspace = true, features = ["client"] }
tracing = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion client/transport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]

Expand Down
2 changes: 1 addition & 1 deletion client/transport/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt;
use futures_channel::mpsc;
use futures_util::sink::SinkExt;
use futures_util::stream::{SplitSink, SplitStream, StreamExt};
use gloo_net::websocket::{futures::WebSocket, Message, WebSocketError};
use gloo_net::websocket::{Message, WebSocketError, futures::WebSocket};
use jsonrpsee_core::async_trait;
use jsonrpsee_core::client::{ReceivedMessage, TransportReceiverT, TransportSenderT};

Expand Down
16 changes: 9 additions & 7 deletions client/transport/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ use std::time::Duration;

use base64::Engine;
use futures_util::io::{BufReader, BufWriter};
use jsonrpsee_core::client::{MaybeSend, ReceivedMessage, TransportReceiverT, TransportSenderT};
use jsonrpsee_core::TEN_MB_SIZE_BYTES;
use jsonrpsee_core::{async_trait, Cow};
use jsonrpsee_core::client::{MaybeSend, ReceivedMessage, TransportReceiverT, TransportSenderT};
use jsonrpsee_core::{Cow, async_trait};
use soketto::connection::CloseReason;
use soketto::connection::Error::Utf8;
use soketto::data::ByteSlice125;
use soketto::handshake::client::{Client as WsHandshakeClient, ServerResponse};
use soketto::{connection, Data, Incoming};
use soketto::{Data, Incoming, connection};
use thiserror::Error;
use tokio::net::TcpStream;
use tokio_util::compat::{Compat, TokioAsyncReadCompatExt};

pub use http::{uri::InvalidUri, HeaderMap, HeaderValue, Uri};
pub use http::{HeaderMap, HeaderValue, Uri, uri::InvalidUri};
pub use soketto::handshake::client::Header;
pub use stream::EitherStream;
pub use tokio::io::{AsyncRead, AsyncWrite};
Expand Down Expand Up @@ -428,7 +428,9 @@ impl WsTransportClientBuilder {
match target.path_and_query.rfind('/') {
Some(offset) => target.path_and_query.replace_range(offset + 1.., &location),
None => {
let e = format!("path_and_query: {location}; this is a bug it must contain `/` please open issue");
let e = format!(
"path_and_query: {location}; this is a bug it must contain `/` please open issue"
);
err = Some(Err(WsHandshakeError::Url(e.into())));
continue;
}
Expand Down Expand Up @@ -638,13 +640,13 @@ fn build_tls_config(cert_store: &CertificateStore) -> Result<tokio_rustls::TlsCo
use rustls_platform_verifier::ConfigVerifierExt;

rustls::ClientConfig::with_platform_verifier()
},
}
#[cfg(not(feature = "tls-rustls-platform-verifier"))]
CertificateStore::Native => {
return Err(WsHandshakeError::CertificateStore(io::Error::new(
io::ErrorKind::Other,
"Native certificate store not supported, either call `Builder::with_custom_cert_store` or enable the `tls-rustls-platform-verifier` feature.",
)))
)));
}
CertificateStore::Custom(cfg) => cfg.clone(),
};
Expand Down
3 changes: 3 additions & 0 deletions client/wasm-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords.workspace = true
readme.workspace = true
publish = true

[lints]
workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
jsonrpsee-types = { workspace = true }
jsonrpsee-client-transport = { workspace = true, features = ["web"] }
Expand Down
1 change: 0 additions & 1 deletion client/wasm-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

//! # jsonrpsee-wasm-client
#![warn(missing_docs, missing_debug_implementations, missing_copy_implementations, unreachable_pub)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg(target_arch = "wasm32")]
Expand Down
3 changes: 3 additions & 0 deletions client/ws-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords.workspace = true
readme.workspace = true
publish = true

[lints]
workspace = true

[dependencies]
http = { workspace = true }
jsonrpsee-types = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions client/ws-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@
//!
//! This library uses `tokio` as the runtime and does not support other runtimes.
#![warn(missing_docs, missing_debug_implementations, missing_copy_implementations, unreachable_pub)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(test)]
mod tests;

pub use http::{HeaderMap, HeaderValue};
pub use jsonrpsee_core::client::async_client::PingConfig;
pub use jsonrpsee_core::client::Client as WsClient;
pub use jsonrpsee_core::client::async_client::PingConfig;
pub use jsonrpsee_types as types;

use jsonrpsee_client_transport::ws::{AsyncRead, AsyncWrite, WsTransportClientBuilder};
use jsonrpsee_core::client::{ClientBuilder, Error, IdKind, MaybeSend, TransportReceiverT, TransportSenderT};
use jsonrpsee_core::TEN_MB_SIZE_BYTES;
use jsonrpsee_core::client::{ClientBuilder, Error, IdKind, MaybeSend, TransportReceiverT, TransportSenderT};
use std::time::Duration;
use url::Url;

Expand Down
6 changes: 3 additions & 3 deletions client/ws-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::types::error::{ErrorCode, ErrorObject};
use crate::WsClientBuilder;
use crate::types::error::{ErrorCode, ErrorObject};

use jsonrpsee_core::client::{
BatchResponse, ClientT, Error, IdKind, Subscription, SubscriptionClientT, SubscriptionCloseReason,
};
use jsonrpsee_core::params::BatchRequestBuilder;
use jsonrpsee_core::{rpc_params, DeserializeOwned};
use jsonrpsee_core::{DeserializeOwned, rpc_params};
use jsonrpsee_test_utils::TimeoutFutureExt;
use jsonrpsee_test_utils::helpers::*;
use jsonrpsee_test_utils::mocks::{Id, WebSocketTestServer};
use jsonrpsee_test_utils::TimeoutFutureExt;
use jsonrpsee_types::error::ErrorObjectOwned;
use jsonrpsee_types::{Notification, SubscriptionId, SubscriptionPayload, SubscriptionResponse};
use serde_json::Value as JsonValue;
Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords.workspace = true
readme.workspace = true
publish = true

[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
jsonrpsee-types = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

//! Shared utilities for `jsonrpsee`.
#![warn(missing_docs, missing_debug_implementations, missing_copy_implementations, unreachable_pub)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]

Expand Down Expand Up @@ -87,10 +86,10 @@ pub mod __reexports {
pub use super::proc_macros_support::*;
}

pub use serde::{de::DeserializeOwned, Serialize};
pub use serde::{Serialize, de::DeserializeOwned};
pub use serde_json::{
to_value as to_json_value, value::to_raw_value as to_json_raw_value, value::RawValue as JsonRawValue,
Value as JsonValue,
Value as JsonValue, to_value as to_json_value, value::RawValue as JsonRawValue,
value::to_raw_value as to_json_raw_value,
};
pub use std::borrow::Cow;

Expand Down
18 changes: 3 additions & 15 deletions core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ impl Default for ObjectParams {

impl ToRpcParams for ObjectParams {
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, serde_json::Error> {
if let Some(json) = self.0.build() {
RawValue::from_string(json).map(Some)
} else {
Ok(None)
}
if let Some(json) = self.0.build() { RawValue::from_string(json).map(Some) } else { Ok(None) }
}
}

Expand Down Expand Up @@ -210,11 +206,7 @@ impl Default for ArrayParams {

impl ToRpcParams for ArrayParams {
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, serde_json::Error> {
if let Some(json) = self.0.build() {
RawValue::from_string(json).map(Some)
} else {
Ok(None)
}
if let Some(json) = self.0.build() { RawValue::from_string(json).map(Some) } else { Ok(None) }
}
}

Expand Down Expand Up @@ -246,11 +238,7 @@ impl<'a> BatchRequestBuilder<'a> {
/// Finish the building process and return a valid batch parameter.
#[allow(clippy::type_complexity)]
pub fn build(self) -> Result<Vec<(&'a str, Option<Box<RawValue>>)>, EmptyBatchRequest> {
if self.0.is_empty() {
Err(EmptyBatchRequest)
} else {
Ok(self.0)
}
if self.0.is_empty() { Err(EmptyBatchRequest) } else { Ok(self.0) }
}

/// Get an iterator over the batch request.
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/client_subscription_drop_oldest_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use std::net::SocketAddr;
use std::time::Duration;

use futures::{Stream, StreamExt};
use jsonrpsee::core::client::{Subscription, SubscriptionClientT};
use jsonrpsee::core::DeserializeOwned;
use jsonrpsee::core::client::{Subscription, SubscriptionClientT};
use jsonrpsee::rpc_params;
use jsonrpsee::server::{RpcModule, Server, SubscriptionMessage};
use jsonrpsee::ws_client::WsClientBuilder;
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
use tokio_stream::wrappers::BroadcastStream;
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use jsonrpsee::core::client::ClientT;
use jsonrpsee::http_client::HttpClient;
use jsonrpsee::rpc_params;
use jsonrpsee::server::{RpcModule, Server};
use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer};
use tower_http::LatencyUnit;
use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer};
use tracing_subscriber::util::SubscriberInitExt;

#[tokio::main]
Expand Down
Loading

0 comments on commit 9272591

Please sign in to comment.