Skip to content

Commit

Permalink
chore: apply clippy lints to public API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomaseizinger authored Oct 16, 2023
1 parent 7c6f75e commit ce91c1c
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand All @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
disallowed-methods = [
{ path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" },
]
avoid-breaking-exported-api = false
5 changes: 5 additions & 0 deletions identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions identity/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
6 changes: 6 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions transports/pnet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.23.1 - unreleased

<!-- Interal changes:
- Allow new clippy lint.
-->

## 0.23.0

- Raise MSRV to 1.65.
Expand Down
2 changes: 1 addition & 1 deletion transports/pnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
1 change: 1 addition & 0 deletions transports/pnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions transports/webrtc-websys/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion transports/webrtc-websys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions transports/webrtc-websys/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions transports/webrtc-websys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum Error {
InvalidMultiaddr(&'static str),

#[error("JavaScript error: {0}")]
JsError(String),
Js(String),

#[error("JavaScript typecasting failed")]
JsCastFailed,
Expand All @@ -34,7 +34,7 @@ impl Error {
"Unknown error".to_string()
};

Error::JsError(s)
Error::Js(s)
}
}

Expand All @@ -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())
}
}

0 comments on commit ce91c1c

Please sign in to comment.