diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a563786..607a09f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,13 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build on ${{ matrix.os }} - run: cargo build --verbose + - uses: dtolnay/rust-toolchain@nightly + with: + components: clippy, rustfmt + + - name: Validate formatting on ${{ matrix.os }} + run: cargo fmt --all -- --check + - name: Run clippy lints on ${{ matrix.os }} + run: cargo +stable clippy --verbose --no-deps --all-features - name: Run tests on ${{ matrix.os }} - run: cargo test --verbose + run: cargo +stable test --verbose --all-features diff --git a/src/client.rs b/src/client.rs index ab5f21e..dadb8a8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -547,7 +547,8 @@ impl Client { /// Sets the XP bar visible above hotbar and total experience. /// /// # Arguments - /// * `bar` - Floating value in the range `0.0..=1.0` indicating progress on the XP bar. + /// * `bar` - Floating value in the range `0.0..=1.0` indicating progress on + /// the XP bar. /// * `level` - Number above the XP bar. /// * `total_xp` - TODO. pub fn set_level(&mut self, bar: f32, level: i32, total_xp: i32) { @@ -562,7 +563,8 @@ impl Client { /// You can read more about hunger and saturation [here](https://minecraft.fandom.com/wiki/Food#Hunger_vs._Saturation). /// /// # Arguments - /// * `health` - Float in range `0.0..=20.0`. Value `<=0` is legal and will kill the player. + /// * `health` - Float in range `0.0..=20.0`. Value `<=0` is legal and will + /// kill the player. /// * `food` - Integer in range `0..=20`. /// * `food_saturation` - Float in range `0.0..=5.0`. pub fn set_health_and_food(&mut self, health: f32, food: i32, food_saturation: f32) { diff --git a/src/entity.rs b/src/entity.rs index d9e0bdf..f594694 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -652,13 +652,13 @@ impl From for S2cPlayPacket { #[cfg(test)] mod tests { use std::num::NonZeroU32; + use uuid::Uuid; + use super::{Entities, EntityId, EntityKind}; - use crate::{ - config::Config, - slab_versioned::Key, - server::Server - }; + use crate::config::Config; + use crate::server::Server; + use crate::slab_versioned::Key; /// Created for the sole purpose of use during unit tests. struct MockConfig; @@ -670,8 +670,10 @@ mod tests { type ChunkState = (); type PlayerListState = (); - fn max_connections(&self) -> usize { 10 } - fn update(&self, _server: &mut Server) { } + fn max_connections(&self) -> usize { + 10 + } + fn update(&self, _server: &mut Server) {} } #[test] @@ -680,7 +682,7 @@ mod tests { let network_id: i32 = 8675309; let entity_id = EntityId(Key::new( 202298, - NonZeroU32::new(network_id as u32).expect("Value given should never be zero!") + NonZeroU32::new(network_id as u32).expect("Value given should never be zero!"), )); let uuid = Uuid::from_bytes([2; 16]); assert!(entities.is_empty()); @@ -697,7 +699,8 @@ mod tests { let (player_id, player_entity) = entities.insert(EntityKind::Player, 1); assert_eq!(player_entity.state, 1); assert_eq!(entities.get(player_id).unwrap().state, 1); - let mut_player_entity = entities.get_mut(player_id) + let mut_player_entity = entities + .get_mut(player_id) .expect("Failed to get mutable reference"); mut_player_entity.state = 100; assert_eq!(entities.get(player_id).unwrap().state, 100); @@ -709,10 +712,12 @@ mod tests { let mut entities: Entities = Entities::new(); let uuid = Uuid::from_bytes([2; 16]); assert!(entities.is_empty()); - let (zombie_id, zombie_entity) = entities.insert_with_uuid(EntityKind::Zombie, uuid, 1) + let (zombie_id, zombie_entity) = entities + .insert_with_uuid(EntityKind::Zombie, uuid, 1) .expect("Unexpected Uuid collision when inserting to an empty collection"); assert_eq!(zombie_entity.state, 1); - let maybe_zombie = entities.get_with_uuid(uuid) + let maybe_zombie = entities + .get_with_uuid(uuid) .expect("Uuid lookup failed on item already added to this collection"); assert_eq!(zombie_id, maybe_zombie); assert_eq!(entities.len(), 1); @@ -726,14 +731,18 @@ mod tests { assert_eq!(boat_entity.state, 12); let (cat_id, cat_entity) = entities.insert(EntityKind::Cat, 75); assert_eq!(cat_entity.state, 75); - let maybe_boat_id = entities.get_with_network_id(boat_id.0.version.get() as i32) + let maybe_boat_id = entities + .get_with_network_id(boat_id.0.version.get() as i32) .expect("Network id lookup failed on item already added to this collection"); - let maybe_boat = entities.get(maybe_boat_id) + let maybe_boat = entities + .get(maybe_boat_id) .expect("Failed to look up item already added to collection"); assert_eq!(maybe_boat.state, 12); - let maybe_cat_id = entities.get_with_network_id(cat_id.0.version.get() as i32) + let maybe_cat_id = entities + .get_with_network_id(cat_id.0.version.get() as i32) .expect("Network id lookup failed on item already added to this collection"); - let maybe_cat = entities.get(maybe_cat_id) + let maybe_cat = entities + .get(maybe_cat_id) .expect("Failed to look up item already added to collection"); assert_eq!(maybe_cat.state, 75); assert_eq!(entities.len(), 2); @@ -744,7 +753,8 @@ mod tests { let mut entities: Entities = Entities::new(); assert!(entities.is_empty()); let (player_id, _) = entities.insert(EntityKind::Player, 1); - let player_state = entities.remove(player_id) + let player_state = entities + .remove(player_id) .expect("Failed to remove an item from the collection"); assert_eq!(player_state, 1); } @@ -759,7 +769,7 @@ mod tests { let (goat_id, _) = entities.insert(EntityKind::Goat, 120); let (horse_id, _) = entities.insert(EntityKind::Horse, 30); assert_eq!(entities.len(), 5); - entities.retain(|_id, entity| entity.state > 100 ); + entities.retain(|_id, entity| entity.state > 100); assert_eq!(entities.len(), 2); assert!(entities.get(fox_id).is_some()); assert!(entities.get(goat_id).is_some()); @@ -767,4 +777,4 @@ mod tests { assert!(entities.get(turtle_id).is_none()); assert!(entities.get(horse_id).is_none()); } -} \ No newline at end of file +} diff --git a/src/ident.rs b/src/ident.rs index 1cefa72..0aedebc 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -1,6 +1,4 @@ //! Namespaced identifiers. -//! -//! use std::borrow::Cow; use std::io::Write; diff --git a/src/protocol/slot.rs b/src/protocol/slot.rs index beab216..6ddb7d4 100644 --- a/src/protocol/slot.rs +++ b/src/protocol/slot.rs @@ -1,6 +1,7 @@ -use byteorder::ReadBytesExt; use std::io::Write; +use byteorder::ReadBytesExt; + use crate::nbt::Compound; use crate::protocol::{Decode, Encode, VarInt}; @@ -58,9 +59,10 @@ impl Decode for Slot { #[cfg(test)] mod tests { - use super::*; use serde_nbt::Value; + use super::*; + #[test] fn slot_with_nbt() { let mut buf: Vec = Vec::new();