mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
derive FromStr
This commit is contained in:
parent
023d2c6f40
commit
68416d6025
2 changed files with 15 additions and 22 deletions
|
|
@ -7,16 +7,26 @@ use crate::demo::packet::datatable::{ClassId, SendTable, SendTableName, ServerCl
|
||||||
use crate::demo::parser::ParseBitSkip;
|
use crate::demo::parser::ParseBitSkip;
|
||||||
use crate::demo::sendprop::{SendProp, SendPropDefinition, SendPropValue};
|
use crate::demo::sendprop::{SendProp, SendPropDefinition, SendPropValue};
|
||||||
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||||
use parse_display::Display;
|
use parse_display::{Display, FromStr};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hint::unreachable_unchecked;
|
use std::hint::unreachable_unchecked;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Display, Ord, PartialOrd,
|
Debug,
|
||||||
|
Copy,
|
||||||
|
Clone,
|
||||||
|
PartialEq,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
Display,
|
||||||
|
Ord,
|
||||||
|
PartialOrd,
|
||||||
|
FromStr,
|
||||||
)]
|
)]
|
||||||
pub struct EntityId(u32);
|
pub struct EntityId(u32);
|
||||||
|
|
||||||
|
|
@ -26,14 +36,6 @@ impl From<u32> for EntityId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for EntityId {
|
|
||||||
type Err = ParseIntError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
|
||||||
u32::from_str(s).map(EntityId::from)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(BitRead, Clone, Copy, Debug, PartialEq, Eq, Serialize_repr, Deserialize_repr)]
|
#[derive(BitRead, Clone, Copy, Debug, PartialEq, Eq, Serialize_repr, Deserialize_repr)]
|
||||||
#[discriminant_bits = 2]
|
#[discriminant_bits = 2]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::demo::sendprop::{
|
||||||
SendPropDefinition, SendPropDefinitionIndex, SendPropFlag, SendPropName, SendPropType,
|
SendPropDefinition, SendPropDefinitionIndex, SendPropFlag, SendPropName, SendPropType,
|
||||||
};
|
};
|
||||||
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
use crate::{MalformedDemoError, Parse, ParseError, ParserState, ReadResult, Result, Stream};
|
||||||
use parse_display::Display;
|
use parse_display::{Display, FromStr};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
@ -13,19 +13,10 @@ use std::fmt;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[derive(BitRead, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Display)]
|
#[derive(BitRead, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Display, FromStr)]
|
||||||
pub struct ClassId(u16);
|
pub struct ClassId(u16);
|
||||||
|
|
||||||
impl FromStr for ClassId {
|
|
||||||
type Err = ParseIntError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
|
||||||
u16::from_str(s).map(|num| ClassId(num))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u16> for ClassId {
|
impl From<u16> for ClassId {
|
||||||
fn from(int: u16) -> Self {
|
fn from(int: u16) -> Self {
|
||||||
ClassId(int)
|
ClassId(int)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue