chore: apply clippy lints to public API

By default, clippy doesn't suggest changes if it would break the public API. Whilst a sensible default, it makes us miss certain opportunities to follow conventions correctly. When a new lint is added, we can always temporarily allow it and make a change in the next breaking release but I think it is better to be aware of the lint than having it automatically silenced.

Pull-Request: #4653.
This commit is contained in:
Thomas Eizinger 2023-10-17 08:57:36 +11:00 committed by GitHub
parent 7c6f75eaf2
commit ce91c1c22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 47 additions and 20 deletions

6
Cargo.lock generated
View File

@ -2630,7 +2630,7 @@ dependencies = [
[[package]]
name = "libp2p-identity"
version = "0.2.5"
version = "0.2.6"
dependencies = [
"asn1_der",
"base64 0.21.4",
@ -2884,7 +2884,7 @@ dependencies = [
[[package]]
name = "libp2p-pnet"
version = "0.23.0"
version = "0.23.1"
dependencies = [
"futures",
"libp2p-core",
@ -3229,7 +3229,7 @@ dependencies = [
[[package]]
name = "libp2p-webrtc-websys"
version = "0.1.0-alpha"
version = "0.2.0-alpha"
dependencies = [
"bytes",
"futures",

View File

@ -83,7 +83,7 @@ libp2p-dns = { version = "0.40.1", path = "transports/dns" }
libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.45.2", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.43.1", path = "protocols/identify" }
libp2p-identity = { version = "0.2.5" }
libp2p-identity = { version = "0.2.6" }
libp2p-kad = { version = "0.44.6", path = "protocols/kad" }
libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.1.0", path = "misc/memory-connection-limits" }
@ -94,7 +94,7 @@ libp2p-noise = { version = "0.43.2", path = "transports/noise" }
libp2p-perf = { version = "0.2.0", path = "protocols/perf" }
libp2p-ping = { version = "0.43.1", path = "protocols/ping" }
libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" }
libp2p-pnet = { version = "0.23.0", path = "transports/pnet" }
libp2p-pnet = { version = "0.23.1", path = "transports/pnet" }
libp2p-quic = { version = "0.9.3", path = "transports/quic" }
libp2p-relay = { version = "0.16.2", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.13.1", path = "protocols/rendezvous" }
@ -110,7 +110,7 @@ libp2p-uds = { version = "0.39.0", path = "transports/uds" }
libp2p-wasm-ext = { version = "0.40.0", path = "transports/wasm-ext" }
libp2p-webrtc = { version = "0.6.1-alpha", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.1.0", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.1.0-alpha", path = "transports/webrtc-websys" }
libp2p-webrtc-websys = { version = "0.2.0-alpha", path = "transports/webrtc-websys" }
libp2p-websocket = { version = "0.42.1", path = "transports/websocket" }
libp2p-websocket-websys = { version = "0.2.0", path = "transports/websocket-websys" }
libp2p-webtransport-websys = { version = "0.1.0", path = "transports/webtransport-websys" }

View File

@ -1,3 +1,4 @@
disallowed-methods = [
{ path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" },
]
avoid-breaking-exported-api = false

View File

@ -1,3 +1,8 @@
## 0.2.6
- Make `PeerId::to_bytes` and `PeerId::to_base58` take `self` by value to follow Rust convention of `Copy` types.
See [PR 4653](https://github.com/libp2p/rust-libp2p/pull/4653).
## 0.2.5
- Fix usage of HKDF within `Keypair::derive_secret`.

View File

@ -1,6 +1,6 @@
[package]
name = "libp2p-identity"
version = "0.2.5"
version = "0.2.6"
edition = "2021"
description = "Data structures and algorithms for identifying peers in libp2p."
rust-version = { workspace = true }

View File

@ -114,8 +114,9 @@ pub use keypair::{Keypair, PublicKey};
#[cfg(feature = "peerid")]
pub use peer_id::{ParseError, PeerId};
#[derive(Debug, PartialEq, Eq)]
/// The type of key a `KeyPair` is holding.
#[derive(Debug, PartialEq, Eq)]
#[allow(clippy::upper_case_acronyms)]
pub enum KeyType {
Ed25519,
RSA,

View File

@ -109,12 +109,12 @@ impl PeerId {
}
/// Returns a raw bytes representation of this `PeerId`.
pub fn to_bytes(&self) -> Vec<u8> {
pub fn to_bytes(self) -> Vec<u8> {
self.multihash.to_bytes()
}
/// Returns a base-58 encoded string of this `PeerId`.
pub fn to_base58(&self) -> String {
pub fn to_base58(self) -> String {
bs58::encode(self.to_bytes()).into_string()
}
}

View File

@ -3,6 +3,12 @@
- Deprecate `gossipsub::Config::idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`.
See [PR 4648].
<!-- Interal changes:
- Allow new clippy lint.
-->
[PR 4648]: (https://github.com/libp2p/rust-libp2p/pull/4648)
<!-- Internal changes

View File

@ -2787,7 +2787,7 @@ where
let signature = {
let message = proto::Message {
from: Some(author.clone().to_bytes()),
from: Some(author.to_bytes()),
data: Some(data.clone()),
seqno: Some(sequence_number.to_be_bytes().to_vec()),
topic: topic.clone().into_string(),

View File

@ -1,3 +1,11 @@
## 0.23.1 - unreleased
<!-- Interal changes:
- Allow new clippy lint.
-->
## 0.23.0
- Raise MSRV to 1.65.

View File

@ -3,7 +3,7 @@ name = "libp2p-pnet"
edition = "2021"
rust-version = { workspace = true }
description = "Private swarm support for libp2p"
version = "0.23.0"
version = "0.23.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -159,6 +159,7 @@ impl fmt::Display for Fingerprint {
/// Error when parsing a PreSharedKey
#[derive(Clone, Debug, PartialEq, Eq)]
#[allow(clippy::enum_variant_names)] // Maybe fix at some stage, not important now.
pub enum KeyParseError {
/// file does not have the expected structure
InvalidKeyFile,

View File

@ -1,3 +1,8 @@
## 0.2.0-alpha - unreleased
- Rename `Error::JsError` to `Error::Js`.
See [PR 4653](https://github.com/libp2p/rust-libp2p/pull/4653)
## 0.1.0-alpha
- Initial alpha release.

View File

@ -8,7 +8,7 @@ license = "MIT"
name = "libp2p-webrtc-websys"
repository = "https://github.com/libp2p/rust-libp2p"
rust-version = { workspace = true }
version = "0.1.0-alpha"
version = "0.2.0-alpha"
publish = true
[dependencies]

View File

@ -252,11 +252,11 @@ impl RtcPeerConnection {
let sdp = &self
.inner
.local_description()
.ok_or_else(|| Error::JsError("No local description".to_string()))?
.ok_or_else(|| Error::Js("No local description".to_string()))?
.sdp();
let fingerprint = parse_fingerprint(sdp)
.ok_or_else(|| Error::JsError("No fingerprint in SDP".to_string()))?;
let fingerprint =
parse_fingerprint(sdp).ok_or_else(|| Error::Js("No fingerprint in SDP".to_string()))?;
Ok(fingerprint)
}

View File

@ -8,7 +8,7 @@ pub enum Error {
InvalidMultiaddr(&'static str),
#[error("JavaScript error: {0}")]
JsError(String),
Js(String),
#[error("JavaScript typecasting failed")]
JsCastFailed,
@ -34,7 +34,7 @@ impl Error {
"Unknown error".to_string()
};
Error::JsError(s)
Error::Js(s)
}
}
@ -46,12 +46,12 @@ impl std::convert::From<wasm_bindgen::JsValue> for Error {
impl From<String> for Error {
fn from(value: String) -> Self {
Error::JsError(value)
Error::Js(value)
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Error::JsError(value.to_string())
Error::Js(value.to_string())
}
}