mirror of
https://git.mentality.rip/numas13/xash3d-master.git
synced 2025-01-22 04:44:31 +00:00
protocol: remove thiserror
This commit is contained in:
parent
7c53bc40e3
commit
da06045f18
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -719,7 +719,6 @@ version = "0.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"log",
|
"log",
|
||||||
"thiserror",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -12,6 +12,5 @@ homepage = "https://xash.su"
|
|||||||
repository = "https://git.mentality.rip/numas13/xash3d-master"
|
repository = "https://git.mentality.rip/numas13/xash3d-master"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = "1.0.49"
|
|
||||||
log = "0.4.18"
|
log = "0.4.18"
|
||||||
bitflags = "2.4"
|
bitflags = "2.4"
|
||||||
|
@ -6,43 +6,51 @@ use std::{
|
|||||||
mem, str,
|
mem, str,
|
||||||
};
|
};
|
||||||
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use super::color;
|
use super::color;
|
||||||
use super::wrappers::Str;
|
use super::wrappers::Str;
|
||||||
|
|
||||||
/// The error type for `Cursor` and `CursorMut`.
|
/// The error type for `Cursor` and `CursorMut`.
|
||||||
#[derive(Error, Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum CursorError {
|
pub enum CursorError {
|
||||||
/// Invalid number.
|
/// Invalid number.
|
||||||
#[error("Invalid number")]
|
|
||||||
InvalidNumber,
|
InvalidNumber,
|
||||||
/// Invalid string.
|
/// Invalid string.
|
||||||
#[error("Invalid string")]
|
|
||||||
InvalidString,
|
InvalidString,
|
||||||
/// Invalid boolean.
|
/// Invalid boolean.
|
||||||
#[error("Invalid boolean")]
|
|
||||||
InvalidBool,
|
InvalidBool,
|
||||||
/// Invalid table entry.
|
/// Invalid table entry.
|
||||||
#[error("Invalid table key")]
|
|
||||||
InvalidTableKey,
|
InvalidTableKey,
|
||||||
/// Invalid table entry.
|
/// Invalid table entry.
|
||||||
#[error("Invalid table entry")]
|
|
||||||
InvalidTableValue,
|
InvalidTableValue,
|
||||||
/// Table end found.
|
/// Table end found.
|
||||||
#[error("Table end")]
|
|
||||||
TableEnd,
|
TableEnd,
|
||||||
/// Expected data not found.
|
/// Expected data not found.
|
||||||
#[error("Expected data not found")]
|
|
||||||
Expect,
|
Expect,
|
||||||
/// An unexpected data found.
|
/// An unexpected data found.
|
||||||
#[error("Unexpected data")]
|
|
||||||
ExpectEmpty,
|
ExpectEmpty,
|
||||||
/// Buffer size is no enougth to decode or encode a packet.
|
/// Buffer size is no enougth to decode or encode a packet.
|
||||||
#[error("Unexpected end of buffer")]
|
|
||||||
UnexpectedEnd,
|
UnexpectedEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for CursorError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let s = match self {
|
||||||
|
Self::InvalidNumber => "Invalid number",
|
||||||
|
Self::InvalidString => "Invalid string",
|
||||||
|
Self::InvalidBool => "Invalid boolean",
|
||||||
|
Self::InvalidTableKey => "Invalid table key",
|
||||||
|
Self::InvalidTableValue => "Invalid table entry",
|
||||||
|
Self::TableEnd => "Table end",
|
||||||
|
Self::Expect => "Expected data not found",
|
||||||
|
Self::ExpectEmpty => "Unexpected data",
|
||||||
|
Self::UnexpectedEnd => "Unexpected end of buffer",
|
||||||
|
};
|
||||||
|
s.fmt(fmt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for CursorError {}
|
||||||
|
|
||||||
pub type Result<T, E = CursorError> = std::result::Result<T, E>;
|
pub type Result<T, E = CursorError> = std::result::Result<T, E>;
|
||||||
|
|
||||||
pub trait GetKeyValue<'a>: Sized {
|
pub trait GetKeyValue<'a>: Sized {
|
||||||
|
@ -20,11 +20,11 @@ pub mod master;
|
|||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod wrappers;
|
pub mod wrappers;
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub use cursor::CursorError;
|
pub use cursor::CursorError;
|
||||||
pub use server_info::ServerInfo;
|
pub use server_info::ServerInfo;
|
||||||
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use crate::filter::Version;
|
use crate::filter::Version;
|
||||||
|
|
||||||
/// Current protocol version.
|
/// Current protocol version.
|
||||||
@ -33,30 +33,53 @@ pub const PROTOCOL_VERSION: u8 = 49;
|
|||||||
pub const CLIENT_VERSION: Version = Version::new(0, 20);
|
pub const CLIENT_VERSION: Version = Version::new(0, 20);
|
||||||
|
|
||||||
/// The error type for decoding and encoding packets.
|
/// The error type for decoding and encoding packets.
|
||||||
#[derive(Error, Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failed to decode a packet.
|
/// Failed to decode a packet.
|
||||||
#[error("Invalid packet")]
|
|
||||||
InvalidPacket,
|
InvalidPacket,
|
||||||
/// Invalid region.
|
/// Invalid region.
|
||||||
#[error("Invalid region")]
|
|
||||||
InvalidRegion,
|
InvalidRegion,
|
||||||
/// Invalid client announce IP.
|
/// Invalid client announce IP.
|
||||||
#[error("Invalid client announce IP")]
|
|
||||||
InvalidClientAnnounceIp,
|
InvalidClientAnnounceIp,
|
||||||
/// Invalid last IP.
|
/// Invalid last IP.
|
||||||
#[error("Invalid last server IP")]
|
|
||||||
InvalidQueryServersLast,
|
InvalidQueryServersLast,
|
||||||
/// Server protocol version is not supported.
|
/// Server protocol version is not supported.
|
||||||
#[error("Invalid protocol version")]
|
|
||||||
InvalidProtocolVersion,
|
InvalidProtocolVersion,
|
||||||
/// Cursor error.
|
/// Cursor error.
|
||||||
#[error("{0}")]
|
CursorError(CursorError),
|
||||||
CursorError(#[from] CursorError),
|
|
||||||
/// Invalid value for server add packet.
|
/// Invalid value for server add packet.
|
||||||
#[error("Invalid value for server add key `{0}`: {1}")]
|
InvalidServerValue(&'static str, CursorError),
|
||||||
InvalidServerValue(&'static str, #[source] CursorError),
|
|
||||||
/// Invalid value for query servers packet.
|
/// Invalid value for query servers packet.
|
||||||
#[error("Invalid value for filter key `{0}`: {1}")]
|
InvalidFilterValue(&'static str, CursorError),
|
||||||
InvalidFilterValue(&'static str, #[source] CursorError),
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::InvalidPacket => "Invalid packet".fmt(fmt),
|
||||||
|
Self::InvalidRegion => "Invalid region".fmt(fmt),
|
||||||
|
Self::InvalidClientAnnounceIp => "Invalid client announce IP".fmt(fmt),
|
||||||
|
Self::InvalidQueryServersLast => "Invalid last server IP".fmt(fmt),
|
||||||
|
Self::InvalidProtocolVersion => "Invalid protocol version".fmt(fmt),
|
||||||
|
Self::CursorError(source) => source.fmt(fmt),
|
||||||
|
Self::InvalidServerValue(key, source) => {
|
||||||
|
write!(
|
||||||
|
fmt,
|
||||||
|
"Invalid value for server add key `{}`: {}",
|
||||||
|
key, source
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Self::InvalidFilterValue(key, source) => {
|
||||||
|
write!(fmt, "Invalid value for filter key `{}`: {}", key, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
|
impl From<CursorError> for Error {
|
||||||
|
fn from(source: CursorError) -> Self {
|
||||||
|
Self::CursorError(source)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user