error display + remove unused imports

This commit is contained in:
MeexReay 2024-05-25 02:12:41 +03:00
parent abb717f4cf
commit a3fd9dc40b
3 changed files with 24 additions and 14 deletions

View file

@ -1,9 +1,5 @@
use std::io::{Write, Read};
use std::net::{TcpStream, ToSocketAddrs};
use flate2::read::ZlibDecoder;
use flate2::write::ZlibEncoder;
use flate2::{Compress, Compression, Decompress, FlushCompress, Status, FlushDecompress};
use std::{error::Error, fmt, io::{Read, Write}, net::{TcpStream, ToSocketAddrs}};
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
use bytebuffer::ByteBuffer;
use uuid::Uuid;
@ -34,6 +30,14 @@ pub enum ProtocolError {
UnsignedShortError
}
impl fmt::Display for ProtocolError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "An protocol error occured")
}
}
impl Error for ProtocolError {}
#[derive(Debug)]
pub struct Packet {
pub id: u8,
@ -358,7 +362,7 @@ impl DataBufferReader for Packet {
fn read_bytes(&mut self, size: usize) -> Result<Vec<u8>, ProtocolError> {
let mut buf = vec![0; size];
match self.buffer.read_exact(&mut buf) {
Ok(i) => Ok(buf),
Ok(_) => Ok(buf),
Err(_) => Err(ProtocolError::ReadError),
}
}