first commit
This commit is contained in:
52
src-tauri/src/serial_core/error.rs
Normal file
52
src-tauri/src/serial_core/error.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum SerialError {
|
||||
OpenError,
|
||||
CloseError,
|
||||
ScanError,
|
||||
InvalidConfig,
|
||||
AlreadyConnected,
|
||||
StateError,
|
||||
NoRecordedData,
|
||||
ExportError,
|
||||
ImportError,
|
||||
}
|
||||
|
||||
impl fmt::Display for SerialError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SerialError::OpenError => write!(f, "Opening Error"),
|
||||
SerialError::CloseError => write!(f, "Closing Error"),
|
||||
SerialError::ScanError => write!(f, "Scan Error"),
|
||||
SerialError::InvalidConfig => write!(f, "Invalid Config"),
|
||||
SerialError::AlreadyConnected => write!(f, "Already Connected"),
|
||||
SerialError::StateError => write!(f, "State Error"),
|
||||
SerialError::NoRecordedData => write!(f, "No Recorded Data"),
|
||||
SerialError::ExportError => write!(f, "Export Error"),
|
||||
SerialError::ImportError => write!(f, "Import Error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CodecError {
|
||||
InvalidHeader,
|
||||
InvalidTail,
|
||||
InvalidLength,
|
||||
PayloadTooLarge,
|
||||
}
|
||||
|
||||
impl fmt::Display for CodecError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
CodecError::InvalidHeader => write!(f, "Invalid Header"),
|
||||
CodecError::InvalidTail => write!(f, "Invalid Tail"),
|
||||
CodecError::InvalidLength => write!(f, "Invalid Length"),
|
||||
CodecError::PayloadTooLarge => write!(f, "Payload too large"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CodecError {}
|
||||
Reference in New Issue
Block a user