mirror of
https://github.com/tlsnotary/tlsn-utils.git
synced 2026-01-09 20:57:56 -05:00
chore: fix clippy issues + run clippy in CI (#45)
* Chore: fix clippy issues + run clippy in CI * clippy * clippy * clippy * Formatting
This commit is contained in:
38
.github/workflows/rust.yml
vendored
38
.github/workflows/rust.yml
vendored
@@ -12,20 +12,26 @@ env:
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
if: ( ! github.event.pull_request.draft )
|
||||
name: Build and test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Stable
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Install stable rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
- uses: Swatinem/rust-cache@v2.0.0
|
||||
components: clippy
|
||||
|
||||
- name: "Build"
|
||||
- name: Use caching
|
||||
uses: Swatinem/rust-cache@v2.7.3
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy --all-features --all-targets -- -D warnings
|
||||
|
||||
- name: Build
|
||||
run: cargo build
|
||||
|
||||
- name: "Test"
|
||||
@@ -39,17 +45,11 @@ jobs:
|
||||
run: cargo doc --no-deps --document-private-items --all-features --workspace --examples
|
||||
|
||||
rustfmt:
|
||||
name: Rustfmt
|
||||
name: Check formatting
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Nightly with rustfmt
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
components: rustfmt
|
||||
|
||||
- name: "Check formatting"
|
||||
run: cargo +nightly fmt --check --all
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2.7.3
|
||||
- name: Check formatting
|
||||
run: cargo fmt --check --all
|
||||
@@ -20,8 +20,8 @@ async fn main() {
|
||||
let a = LengthDelimitedCodec::builder().new_framed(a);
|
||||
let b = LengthDelimitedCodec::builder().new_framed(b);
|
||||
|
||||
let a = Framed::new(a, Bincode::default());
|
||||
let b = Framed::new(b, Bincode::default());
|
||||
let a = Framed::new(a, Bincode);
|
||||
let b = Framed::new(b, Bincode);
|
||||
|
||||
tokio::try_join!(alice(a), bob(b)).unwrap();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ mod bincode_impl {
|
||||
type Error = bincode::Error;
|
||||
|
||||
fn deserialize<T: Deserialize>(&mut self, buf: &BytesMut) -> Result<T, Self::Error> {
|
||||
Ok(deserialize(buf)?)
|
||||
deserialize(buf)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ mod tests {
|
||||
fn test_framed() {
|
||||
let (a, b) = duplex(1024);
|
||||
|
||||
let mut a = Bincode::default().new_framed(a.compat());
|
||||
let mut b = Bincode::default().new_framed(b.compat());
|
||||
let mut a = Bincode.new_framed(a.compat());
|
||||
let mut b = Bincode.new_framed(b.compat());
|
||||
|
||||
let a = async {
|
||||
a.send(Ping).await.unwrap();
|
||||
|
||||
@@ -38,15 +38,15 @@ pub trait Stream {
|
||||
/// stream state:
|
||||
///
|
||||
/// - `Poll::Pending` means that this stream's next value is not ready
|
||||
/// yet. Implementations will ensure that the current task will be notified
|
||||
/// when the next value may be ready.
|
||||
/// yet. Implementations will ensure that the current task will be notified
|
||||
/// when the next value may be ready.
|
||||
///
|
||||
/// - `Poll::Ready(Some(val))` means that the stream has successfully
|
||||
/// produced a value, `val`, and may produce further values on subsequent
|
||||
/// `poll_next` calls.
|
||||
/// produced a value, `val`, and may produce further values on subsequent
|
||||
/// `poll_next` calls.
|
||||
///
|
||||
/// - `Poll::Ready(None)` means that the stream has terminated, and
|
||||
/// `poll_next` should not be invoked again.
|
||||
/// `poll_next` should not be invoked again.
|
||||
fn poll_next<Item: Deserialize>(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
|
||||
@@ -44,10 +44,11 @@ impl Iterator for Requests {
|
||||
if self.pos >= self.src.len() {
|
||||
None
|
||||
} else {
|
||||
Some(parse_request_from_bytes(&self.src, self.pos).map(|req| {
|
||||
self.pos += req.span.len();
|
||||
req
|
||||
}))
|
||||
Some(
|
||||
parse_request_from_bytes(&self.src, self.pos).inspect(|req| {
|
||||
self.pos += req.span.len();
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,10 +83,11 @@ impl Iterator for Responses {
|
||||
if self.pos >= self.src.len() {
|
||||
None
|
||||
} else {
|
||||
Some(parse_response_from_bytes(&self.src, self.pos).map(|resp| {
|
||||
self.pos += resp.span.len();
|
||||
resp
|
||||
}))
|
||||
Some(
|
||||
parse_response_from_bytes(&self.src, self.pos).inspect(|resp| {
|
||||
self.pos += resp.span.len();
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,15 +97,15 @@ impl<T: ?Sized> AsRef<RangeSet<usize>> for Span<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> Into<Bytes> for Span<T> {
|
||||
fn into(self) -> Bytes {
|
||||
self.data
|
||||
impl<T: ?Sized> From<Span<T>> for Bytes {
|
||||
fn from(val: Span<T>) -> Self {
|
||||
val.data
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> Into<RangeSet<usize>> for Span<T> {
|
||||
fn into(self) -> RangeSet<usize> {
|
||||
self.indices
|
||||
impl<T: ?Sized> From<Span<T>> for RangeSet<usize> {
|
||||
fn from(val: Span<T>) -> Self {
|
||||
val.indices
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,10 +126,8 @@ where
|
||||
// If we've finished sending, flush the write buffer. If flushing
|
||||
// succeeds then we can return Ready, otherwise we need to keep
|
||||
// trying.
|
||||
if state.is_done() {
|
||||
if pin!(&mut state.io).poll_flush(cx)?.is_ready() {
|
||||
return Poll::Ready(Ok(state.io));
|
||||
}
|
||||
if state.is_done() && pin!(&mut state.io).poll_flush(cx)?.is_ready() {
|
||||
return Poll::Ready(Ok(state.io));
|
||||
}
|
||||
|
||||
self.0 = State::Pending(state);
|
||||
|
||||
@@ -31,6 +31,7 @@ pub fn test_yamux_pair(
|
||||
///
|
||||
/// * `buffer` - The buffer size.
|
||||
/// * `codec` - The codec.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn test_yamux_pair_framed<C: Clone>(
|
||||
buffer: usize,
|
||||
codec: C,
|
||||
|
||||
@@ -54,7 +54,7 @@ pub struct Yamux<Io> {
|
||||
shutdown_notify: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
struct Queue {
|
||||
waiting: HashMap<InternalId, oneshot::Sender<Stream>>,
|
||||
ready: HashMap<InternalId, Stream>,
|
||||
@@ -62,17 +62,6 @@ struct Queue {
|
||||
waker: Option<Waker>,
|
||||
}
|
||||
|
||||
impl Default for Queue {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
waiting: Default::default(),
|
||||
ready: Default::default(),
|
||||
alloc: 0,
|
||||
waker: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Io> Yamux<Io> {
|
||||
/// Returns a new control handle.
|
||||
pub fn control(&self) -> YamuxCtrl {
|
||||
@@ -368,7 +357,9 @@ impl YamuxCtrl {
|
||||
|
||||
let mut queue = self.queue.lock().unwrap();
|
||||
queue.alloc += count;
|
||||
queue.waker.as_ref().map(|waker| waker.wake_by_ref());
|
||||
if let Some(waker) = queue.waker.as_ref() {
|
||||
waker.wake_by_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Closes the yamux connection.
|
||||
@@ -376,12 +367,9 @@ impl YamuxCtrl {
|
||||
self.shutdown_notify.store(true, Ordering::Relaxed);
|
||||
|
||||
// Wake up the connection.
|
||||
self.queue
|
||||
.lock()
|
||||
.unwrap()
|
||||
.waker
|
||||
.as_ref()
|
||||
.map(|waker| waker.wake_by_ref());
|
||||
if let Some(waker) = self.queue.lock().unwrap().waker.as_ref() {
|
||||
waker.wake_by_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +406,9 @@ where
|
||||
// Insert the oneshot into the queue.
|
||||
queue.waiting.insert(internal_id, sender);
|
||||
// Wake up the connection.
|
||||
queue.waker.as_ref().map(|waker| waker.wake_by_ref());
|
||||
if let Some(waker) = queue.waker.as_ref() {
|
||||
waker.wake_by_ref()
|
||||
}
|
||||
|
||||
trace!("waiting for stream");
|
||||
|
||||
@@ -431,7 +421,7 @@ where
|
||||
.inspect(|_| debug!("caller received stream"))
|
||||
.inspect_err(|_| error!("connection cancelled stream"))
|
||||
.map_err(|_| {
|
||||
std::io::Error::other(format!("connection cancelled stream"))
|
||||
std::io::Error::other("connection cancelled stream".to_string())
|
||||
}),
|
||||
_ = self.close_notify.notified().fuse() => {
|
||||
error!("connection closed before stream opened");
|
||||
|
||||
@@ -103,16 +103,16 @@ impl NestedId {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for NestedId {
|
||||
fn to_string(&self) -> String {
|
||||
impl std::fmt::Display for NestedId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
NestedId::String { id, root } => match root {
|
||||
Some(root) => format!("{}/{}", root.to_string(), id),
|
||||
None => id.to_string(),
|
||||
Some(root) => write!(f, "{}/{}", root, id),
|
||||
None => write!(f, "{}", id),
|
||||
},
|
||||
NestedId::Counter { value, root } => match root {
|
||||
Some(root) => format!("{}/{}", root.to_string(), value),
|
||||
None => value.to_string(),
|
||||
Some(root) => write!(f, "{}/{}", root, value),
|
||||
None => write!(f, "{}", value),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ pub trait DifferenceMut<Rhs> {
|
||||
|
||||
impl<T: Copy + Ord> DifferenceMut<Range<T>> for RangeSet<T> {
|
||||
fn difference_mut(&mut self, other: &Range<T>) {
|
||||
if other.is_empty() {
|
||||
return;
|
||||
} else if self.ranges.is_empty() {
|
||||
if other.is_empty() || self.ranges.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ impl<T: Copy + Ord> BitAnd<&RangeSet<T>> for RangeSet<T> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::single_range_in_vec_init)]
|
||||
mod tests {
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ impl<T: Copy + Ord> Subset<RangeSet<T>> for RangeSet<T> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::single_range_in_vec_init)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user