From 5a1998934fbf6a754f2fe327d820f1e33804629d Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 27 Dec 2024 13:35:30 +0900 Subject: [PATCH] Apply rustfmt --- .github/workflows/rust.yml | 9 +++++++ src/net/tcp/stream.rs | 2 +- src/net/udp.rs | 4 +-- src/rt.rs | 2 +- src/sim.rs | 52 ++++++++++---------------------------- 5 files changed, 27 insertions(+), 42 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ae86d1e..778ece3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -24,6 +24,15 @@ jobs: - name: Cargo Test run: cargo test --verbose --features "${{ matrix.features }}" + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - run: cargo fmt --check + clippy: name: Run Clippy runs-on: ${{ matrix.os }} diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index a4d38a0..73b37fa 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -430,4 +430,4 @@ impl Drop for WriteHalf { world.current_host_mut().tcp.close_stream_half(*self.pair); }) } -} \ No newline at end of file +} diff --git a/src/net/udp.rs b/src/net/udp.rs index 9dccc71..de2e9b7 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -308,13 +308,13 @@ impl UdpSocket { Ok(()) } - /// Has no effect in turmoil. API parity with + /// Has no effect in turmoil. API parity with /// https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#method.set_multicast_loop_v6 pub fn set_multicast_loop_v6(&self, _on: bool) -> Result<()> { Ok(()) } - /// Has no effect in turmoil. API parity with + /// Has no effect in turmoil. API parity with /// https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#method.join_multicast_v6 pub fn join_multicast_v6(&self, _multiaddr: &Ipv6Addr, _interface: u32) -> Result<()> { Ok(()) diff --git a/src/rt.rs b/src/rt.rs index 34fa028..bbce466 100644 --- a/src/rt.rs +++ b/src/rt.rs @@ -6,7 +6,7 @@ use futures::Future; use tokio::runtime::Runtime; use tokio::task::JoinHandle; use tokio::task::LocalSet; -use tokio::time::{Duration, Instant, sleep}; +use tokio::time::{sleep, Duration, Instant}; use super::Result; diff --git a/src/sim.rs b/src/sim.rs index f642857..5108e2e 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -10,8 +10,8 @@ use indexmap::IndexMap; use tokio::time::Duration; use tracing::Level; -use crate::{Config, for_pairs, LinksIter, Result, Rt, ToIpAddr, ToIpAddrs, TRACING_TARGET, World}; use crate::host::HostTimer; +use crate::{for_pairs, Config, LinksIter, Result, Rt, ToIpAddr, ToIpAddrs, World, TRACING_TARGET}; /// A handle for interacting with the simulation. pub struct Sim<'a> { @@ -430,17 +430,16 @@ impl<'a> Sim<'a> { #[cfg(test)] mod test { use rand::Rng; + use std::future; use std::{ net::{IpAddr, Ipv4Addr}, rc::Rc, sync::{ - Mutex, - Arc, atomic::{AtomicU64, Ordering}, + Arc, Mutex, }, time::Duration, }; - use std::future; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, @@ -450,9 +449,9 @@ mod test { use crate::net::UdpSocket; use crate::{ - Builder, elapsed, - hold, - net::{TcpListener, TcpStream}, Result, Sim, sim_elapsed, World, + elapsed, hold, + net::{TcpListener, TcpStream}, + sim_elapsed, Builder, Result, Sim, World, }; #[test] @@ -686,7 +685,6 @@ mod test { Ok(()) } - struct Expectation { expect_a_receive: bool, expect_b_receive: bool, @@ -848,41 +846,19 @@ mod test { Ok(()) } - run_with_actions(&[ - Action::PartitionOnewayAB, - ])?; - run_with_actions(&[ - Action::PartitionOnewayBA, - ])?; + run_with_actions(&[Action::PartitionOnewayAB])?; + run_with_actions(&[Action::PartitionOnewayBA])?; + run_with_actions(&[Action::Partition, Action::RepairOnewayAB])?; + run_with_actions(&[Action::Partition, Action::RepairOnewayBA])?; + run_with_actions(&[Action::PartitionOnewayAB, Action::Repair])?; + run_with_actions(&[Action::PartitionOnewayBA, Action::Repair])?; + run_with_actions(&[Action::PartitionOnewayBA, Action::RepairOnewayAB])?; + run_with_actions(&[Action::PartitionOnewayAB, Action::PartitionOnewayBA])?; run_with_actions(&[ Action::Partition, Action::RepairOnewayAB, - ])?; - run_with_actions(&[ - Action::Partition, Action::RepairOnewayBA, ])?; - run_with_actions(&[ - Action::PartitionOnewayAB, - Action::Repair, - ])?; - run_with_actions(&[ - Action::PartitionOnewayBA, - Action::Repair, - ])?; - run_with_actions(&[ - Action::PartitionOnewayBA, - Action::RepairOnewayAB, - ])?; - run_with_actions(&[ - Action::PartitionOnewayAB, - Action::PartitionOnewayBA, - ])?; - run_with_actions(&[ - Action::Partition, - Action::RepairOnewayAB, - Action::RepairOnewayBA - ])?; Ok(()) }