1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 18:24:05 +02:00

clippy fixes

This commit is contained in:
Robin Appelman 2021-07-17 15:37:15 +02:00
commit 5573ec5db2
8 changed files with 42 additions and 58 deletions

View file

@ -15,7 +15,7 @@ impl ConstFnvHash {
let mut i = 0;
while i < bytes.len() {
let byte = bytes[i];
hash = hash ^ (byte as u64);
hash ^= byte as u64;
hash = hash.wrapping_mul(0x100000001b3);
i += 1;
}

View file

@ -10,7 +10,7 @@ use crate::{GameEventError, Parse, ParseError, ParserState, ReadResult, Result,
#[derive(Debug)]
pub struct GameEventMessage {
pub event: Box<GameEvent>,
pub event: GameEvent,
}
impl Parse<'_> for GameEventMessage {
@ -20,12 +20,12 @@ impl Parse<'_> for GameEventMessage {
let event_type: GameEventTypeId = data.read()?;
// game event definitions haven't been sent yet, ignore
if state.event_definitions.len() == 0 {
if state.event_definitions.is_empty() {
return Ok(GameEventMessage {
event: Box::new(GameEvent::Unknown(RawGameEvent {
event: GameEvent::Unknown(RawGameEvent {
event_type: GameEventType::Unknown,
values: Vec::new(),
})),
}),
});
}
@ -37,9 +37,7 @@ impl Parse<'_> for GameEventMessage {
)));
}
};
Ok(GameEventMessage {
event: Box::new(event),
})
Ok(GameEventMessage { event })
}
}

View file

@ -115,11 +115,11 @@ pub struct PacketEntitiesMessage {
pub updated_base_line: bool,
}
fn get_send_table<'a, 'b>(state: &'b ParserState, class: ClassId) -> Result<&'b SendTable> {
fn get_send_table(state: &ParserState, class: ClassId) -> Result<&SendTable> {
state
.send_tables
.get(usize::from(class))
.ok_or_else(|| ParseError::UnknownServerClass(class))
.ok_or(ParseError::UnknownServerClass(class))
}
fn get_entity_for_update(
@ -130,7 +130,7 @@ fn get_entity_for_update(
let class_id = *state
.entity_classes
.get(&entity_index)
.ok_or_else(|| ParseError::UnknownEntity(entity_index))?;
.ok_or(ParseError::UnknownEntity(entity_index))?;
Ok(PacketEntity {
server_class: class_id,
@ -215,7 +215,7 @@ impl PacketEntitiesMessage {
let send_table = state
.send_tables
.get(usize::from(class_index))
.ok_or_else(|| ParseError::UnknownServerClass(class_index))?;
.ok_or(ParseError::UnknownServerClass(class_index))?;
let props = match state.instance_baselines[baseline_index].get(&entity_index) {
Some(baseline) => baseline.clone(),

View file

@ -48,7 +48,7 @@ impl<'a> Parse<'a> for CreateStringTableMessage<'a> {
let decompressed_size: u32 = table_data.read()?;
let compressed_size: u32 = table_data.read()?;
if compressed_size < 4 || compressed_size > 10 * 1024 * 1024 {
if !(4..=10 * 1024 * 1024).contains(&compressed_size) {
return Err(ParseError::InvalidDemo(
"Invalid compressed string table size",
));
@ -145,7 +145,7 @@ impl<'a> Parse<'a> for UpdateStringTableMessage<'a> {
None => return Err(ParseError::StringTableNotFound(table_id)),
}?;
Ok(UpdateStringTableMessage { table_id, entries })
Ok(UpdateStringTableMessage { entries, table_id })
}
}

View file

@ -117,8 +117,8 @@ impl ParseSendTable {
Ok(ParseSendTable {
name,
needs_decoder,
props,
needs_decoder,
})
}
}
@ -184,7 +184,7 @@ impl ParseSendTable {
.iter()
.filter(|prop| !prop.is_exclude())
.filter(|prop| !excludes.iter().any(|exclude| *exclude == prop.identifier()))
.map(|prop| {
.try_for_each(|prop| {
if let Some(table) = prop.get_data_table(tables) {
if prop.flags.contains(SendPropFlag::Collapsible) {
table.get_all_props_iterator_props(tables, excludes, local_props, props)?;
@ -196,8 +196,6 @@ impl ParseSendTable {
}
Ok(())
})
.collect::<Result<()>>()?;
Ok(())
}
}

View file

@ -103,7 +103,7 @@ pub struct ClassList([u8; 10]);
impl ClassList {
/// Get an iterator for all classes played and the number of spawn on the class
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (Class, u8)> + 'a {
pub fn iter(&self) -> impl Iterator<Item = (Class, u8)> + '_ {
self.0
.iter()
.copied()
@ -302,10 +302,10 @@ impl MessageHandler for Analyser {
type Output = MatchState;
fn does_handle(message_type: MessageType) -> bool {
match message_type {
MessageType::GameEvent | MessageType::UserMessage | MessageType::ServerInfo => true,
_ => false,
}
matches!(
message_type,
MessageType::GameEvent | MessageType::UserMessage | MessageType::ServerInfo
)
}
fn handle_message(&mut self, message: &Message, tick: u32) {
@ -323,14 +323,11 @@ impl MessageHandler for Analyser {
}
fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
match table {
"userinfo" => {
let _ = self.parse_user_info(
entry.text.as_ref().map(|s| s.as_ref()),
entry.extra_data.as_ref().map(|data| data.data.clone()),
);
}
_ => {}
if table == "userinfo" {
let _ = self.parse_user_info(
entry.text.as_ref().map(|s| s.as_ref()),
entry.extra_data.as_ref().map(|data| data.data.clone()),
);
}
}

View file

@ -151,20 +151,14 @@ impl MessageHandler for GameStateAnalyser {
type Output = GameState;
fn does_handle(message_type: MessageType) -> bool {
match message_type {
MessageType::PacketEntities => true,
_ => false,
}
matches!(message_type, MessageType::PacketEntities)
}
fn handle_message(&mut self, message: &Message, _tick: u32) {
match message {
Message::PacketEntities(message) => {
for entity in &message.entities {
self.handle_entity(entity);
}
if let Message::PacketEntities(message) = message {
for entity in &message.entities {
self.handle_entity(entity);
}
_ => {}
}
}
@ -308,8 +302,8 @@ impl GameStateAnalyser {
entity.get_prop_by_name("DT_WORLD", "m_WorldMaxs"),
) {
self.state.world = Some(World {
boundary_min: boundary_min.clone(),
boundary_max: boundary_max.clone(),
boundary_min: *boundary_min,
boundary_max: *boundary_max,
})
}
}

View file

@ -151,15 +151,15 @@ impl<'a> ParserState {
}
pub fn does_handle(message_type: MessageType) -> bool {
match message_type {
matches!(
message_type,
MessageType::ServerInfo
| MessageType::NetTick
| MessageType::GameEventList
| MessageType::CreateStringTable
| MessageType::PacketEntities
| MessageType::UpdateStringTable => true,
_ => false,
}
| MessageType::NetTick
| MessageType::GameEventList
| MessageType::CreateStringTable
| MessageType::PacketEntities
| MessageType::UpdateStringTable
)
}
pub fn handle_message(&mut self, message: Message, _tick: u32) {
@ -206,14 +206,11 @@ impl<'a> ParserState {
_index: usize,
entry: &StringTableEntry<'a>,
) {
match table {
"instancebaseline" => {
if let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
self.static_baselines.insert(class_id, baseline);
}
if table == "instancebaseline" {
if let (Some(extra), Ok(class_id)) = (&entry.extra_data, entry.text().parse()) {
let baseline = StaticBaseline::new(class_id, extra.data.to_owned());
self.static_baselines.insert(class_id, baseline);
}
_ => {}
}
}
}