Skip to content

Commit

Permalink
chore: clippy, fail on warn in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Jun 24, 2024
1 parent b455de6 commit 39f39e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
command: clippy -- -D warnings
53 changes: 28 additions & 25 deletions ira/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,40 @@ impl Client {

/// Tries to complete the current packet, returning
/// the packet data if it completes.
///
/// # Errors
///
/// See [`TcpStream::read`].
pub fn next_packet(&mut self) -> io::Result<Vec<u8>> {
let mut partial = mem::take(&mut self.next_packet);

let len = match partial.len {
Some(len) => len,
None => {
while partial.offset < 4 {
let n = match self.stream.read(&mut partial.data[partial.offset..4]) {
Ok(n) => n,
Err(e) => {
self.next_packet = partial;
return Err(e);
}
};

partial.offset += n;
}
let len = if let Some(len) = partial.len {
len
} else {
while partial.offset < 4 {
let n = match self.stream.read(&mut partial.data[partial.offset..4]) {
Ok(n) => n,
Err(e) => {
self.next_packet = partial;
return Err(e);
}
};

partial.offset += n;
}

let len = u32::from_le_bytes([
partial.data[0],
partial.data[1],
partial.data[2],
partial.data[3],
]) as usize;
let len = u32::from_le_bytes([
partial.data[0],
partial.data[1],
partial.data[2],
partial.data[3],
]) as usize;

partial.len = Some(len);
partial.data.resize(len, 0);
partial.offset = 0;
partial.len = Some(len);
partial.data.resize(len, 0);
partial.offset = 0;

len
}
len
};

while partial.offset < len {
Expand Down
8 changes: 4 additions & 4 deletions ira/src/server/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ where
self.owners.insert(*id, client_id);
}
Packet::DeleteInstance { id } => {
self.instances.remove(&id);
self.owners.remove(&id);
self.instances.remove(id);
self.owners.remove(id);
}
Packet::UpdateInstance { id, delta } => {
if let Some(instance) = self.instances.get_mut(&id) {
instance.apply(&delta);
if let Some(instance) = self.instances.get_mut(id) {
instance.apply(delta);
};
}
Packet::DeleteClient => {
Expand Down

0 comments on commit 39f39e7

Please sign in to comment.