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

derive Display where possible

This commit is contained in:
Robin Appelman 2019-08-27 21:43:46 +02:00
commit 66668e3e61
7 changed files with 47 additions and 91 deletions

View file

@ -9,11 +9,12 @@ use super::vector::{Vector, VectorXY};
use crate::demo::message::stringtable::log_base2;
use crate::demo::packet::datatable::SendTableName;
use crate::demo::parser::MalformedSendPropDefinitionError;
use parse_display::Display;
use std::convert::TryInto;
use std::fmt;
use std::rc::Rc;
#[derive(BitRead, PartialEq, Eq, Hash, Debug)]
#[derive(BitRead, PartialEq, Eq, Hash, Debug, Display, Clone)]
pub struct SendPropName(Rc<String>);
impl PartialEq<&str> for SendPropName {
@ -22,18 +23,6 @@ impl PartialEq<&str> for SendPropName {
}
}
impl Clone for SendPropName {
fn clone(&self) -> Self {
SendPropName(Rc::clone(&self.0))
}
}
impl fmt::Display for SendPropName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for SendPropName {
fn from(value: String) -> Self {
Self(Rc::new(value))
@ -213,7 +202,7 @@ impl SendPropDefinition {
}
}
#[derive(BitRead, Copy, Clone, PartialEq, Debug)]
#[derive(BitRead, Copy, Clone, PartialEq, Debug, Display)]
#[discriminant_bits = 5]
pub enum SendPropType {
Int = 0,
@ -226,21 +215,6 @@ pub enum SendPropType {
NumSendPropTypes = 7,
}
impl fmt::Display for SendPropType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SendPropType::Int => write!(f, "Int"),
SendPropType::Float => write!(f, "Float"),
SendPropType::Vector => write!(f, "Vector"),
SendPropType::VectorXY => write!(f, "VectorXY"),
SendPropType::String => write!(f, "String"),
SendPropType::Array => write!(f, "Array"),
SendPropType::DataTable => write!(f, "DataTable"),
SendPropType::NumSendPropTypes => write!(f, "NumSendPropTypes"),
}
}
}
#[derive(EnumFlags, Copy, Clone, PartialEq, Debug)]
#[repr(u16)]
pub enum SendPropFlag {
@ -486,22 +460,13 @@ impl From<Vec<SendPropValue>> for SendPropValue {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Display)]
#[display("{definition.owner_table}::{definition.name} = {value}")]
pub struct SendProp {
pub definition: Rc<SendPropDefinition>,
pub value: SendPropValue,
}
impl fmt::Display for SendProp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}::{} = {}",
self.definition.owner_table, self.definition.name, self.value
)
}
}
pub fn read_var_int(stream: &mut Stream, signed: bool) -> ReadResult<i32> {
let mut result: i32 = 0;