Skip to content

Commit

Permalink
Clippy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Nov 14, 2023
1 parent f33b0c3 commit 5de6ab2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions pygymtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@
steps += 1

ep_time = time.time() - t0
print("Steps per second: {:.0f} | Episode time: {:.2f} | Episode Reward: {:.2f}".format(
steps / ep_time, ep_time, max(ep_reward.values())))
print(f"Steps per second: {steps / ep_time:.0f} | Episode time: {ep_time:.2f} | Episode Reward: {max(ep_reward.values()):.2f}")
34 changes: 17 additions & 17 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pyo3::FromPyObject;
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default)]
pub enum GameMode {
Soccer,
Soccar,
Hoops,
Heatseeker,
Snowday,
Expand Down Expand Up @@ -250,7 +250,7 @@ struct ByteReader<'a> {

impl<'a> ByteReader<'a> {
#[inline]
pub fn new(bytes: &'a [u8]) -> Self {
pub const fn new(bytes: &'a [u8]) -> Self {
Self { idx: 0, bytes }
}

Expand Down Expand Up @@ -284,7 +284,7 @@ impl FromBytesExact for f32 {
impl FromBytes for f32 {
#[inline]
fn from_bytes(bytes: &[u8]) -> Self {
f32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
Self::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
}
}

Expand All @@ -295,7 +295,7 @@ impl FromBytesExact for u32 {
impl FromBytes for u32 {
#[inline]
fn from_bytes(bytes: &[u8]) -> Self {
u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
Self::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
}
}

Expand All @@ -306,7 +306,7 @@ impl FromBytesExact for u64 {
impl FromBytes for u64 {
#[inline]
fn from_bytes(bytes: &[u8]) -> Self {
u64::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]])
Self::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]])
}
}

Expand All @@ -318,8 +318,8 @@ impl FromBytes for Team {
#[inline]
fn from_bytes(bytes: &[u8]) -> Self {
match bytes[0] {
0 => Team::Blue,
1 => Team::Orange,
0 => Self::Blue,
1 => Self::Orange,
_ => unreachable!(),
}
}
Expand All @@ -333,11 +333,11 @@ impl FromBytes for GameMode {
#[inline]
fn from_bytes(bytes: &[u8]) -> Self {
match bytes[0] {
0 => GameMode::Soccer,
1 => GameMode::Hoops,
2 => GameMode::Heatseeker,
3 => GameMode::Snowday,
4 => GameMode::TheVoid,
0 => Self::Soccar,
1 => Self::Hoops,
2 => Self::Heatseeker,
3 => Self::Snowday,
4 => Self::TheVoid,
_ => unreachable!(),
}
}
Expand All @@ -350,7 +350,7 @@ impl FromBytesExact for Vec3 {
impl FromBytes for Vec3 {
fn from_bytes(bytes: &[u8]) -> Self {
let mut reader = ByteReader::new(bytes);
Vec3::new(reader.read(), reader.read(), reader.read())
Self::new(reader.read(), reader.read(), reader.read())
}
}

Expand All @@ -373,7 +373,7 @@ macro_rules! impl_from_bytes_exact {
};
}

pub trait ToBytesExact<const N: usize>: FromBytesExact {
trait ToBytesExact<const N: usize>: FromBytesExact {
fn to_bytes(&self) -> [u8; N];
}

Expand All @@ -384,7 +384,7 @@ struct ByteWriter<const N: usize> {

impl<const N: usize> ByteWriter<N> {
#[inline]
pub fn new() -> Self {
pub const fn new() -> Self {
Self { idx: 0, bytes: [0; N] }
}

Expand All @@ -402,7 +402,7 @@ impl<const N: usize> ByteWriter<N> {

impl ToBytesExact<{ Self::NUM_BYTES }> for bool {
fn to_bytes(&self) -> [u8; Self::NUM_BYTES] {
[*self as u8]
[u8::from(*self)]
}
}

Expand Down Expand Up @@ -610,7 +610,7 @@ impl GameState {

#[inline]
pub fn read_game_mode(bytes: &[u8]) -> GameMode {
GameMode::from_bytes(&bytes[u64::NUM_BYTES + f32::NUM_BYTES..u64::NUM_BYTES + f32::NUM_BYTES + 1])
GameMode::from_bytes(&bytes[(u64::NUM_BYTES + f32::NUM_BYTES)..=(u64::NUM_BYTES + f32::NUM_BYTES)])
}

#[inline]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::all)]

mod bytes;
mod socket;

Expand Down

0 comments on commit 5de6ab2

Please sign in to comment.