#[non_exhaustive]pub enum ModbusError {
NoError,
Timeout(String),
Connection(String),
Protocol(String),
Exception {
function: u8,
code: u8,
},
Serial(String),
Other(String),
}Expand description
Structured Modbus / transport error — no string parsing needed.
Use Display for short UI messages and
detail for full diagnostic logs.
§Short label for UI
Use label for a short human-readable tag
suitable for display in a status bar or error column.
§Example
use oms_modbus::ModbusError;
// Match on specific error kinds
let result: Result<Vec<u16>, ModbusError> = Err(ModbusError::timeout("RTU recv timed out"));
match &result {
Err(ModbusError::Timeout(_)) => println!("Retry or re-connect"),
Err(ModbusError::Exception { function: _, code: _ }) => println!("Modbus exception"),
Err(e) => eprintln!("{} — {}", e.label(), e.detail()),
Ok(_) => {}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
NoError
No error — normal/expected response.
Timeout(String)
Connection(String)
Protocol(String)
Exception
Serial(String)
Other(String)
Implementations§
Source§impl ModbusError
impl ModbusError
Sourcepub fn detail(&self) -> String
pub fn detail(&self) -> String
Full diagnostic message using centralized message prefixes.
Use this for log output; Display gives a short summary for UI.
Sourcepub fn timeout(msg: impl Into<String>) -> Self
pub fn timeout(msg: impl Into<String>) -> Self
Create a timeout error. Covers send and recv timeouts.
Sourcepub fn connection(msg: impl Into<String>) -> Self
pub fn connection(msg: impl Into<String>) -> Self
Create a connection error. Covers TCP connect/read/write failures.
Sourcepub fn protocol(msg: impl Into<String>) -> Self
pub fn protocol(msg: impl Into<String>) -> Self
Create a protocol error. Covers CRC mismatch, slave ID mismatch, invalid PDU.
Sourcepub fn exception(function: u8, code: u8) -> Self
pub fn exception(function: u8, code: u8) -> Self
Create a Modbus exception error from a server response.
Trait Implementations§
Source§impl Clone for ModbusError
impl Clone for ModbusError
Source§fn clone(&self) -> ModbusError
fn clone(&self) -> ModbusError
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModbusError
impl Debug for ModbusError
Source§impl Display for ModbusError
impl Display for ModbusError
Source§impl Error for ModbusError
impl Error for ModbusError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<Error> for ModbusError
impl From<Error> for ModbusError
Source§impl From<ExceptionResponse> for ModbusError
impl From<ExceptionResponse> for ModbusError
Source§fn from(er: ExceptionResponse) -> Self
fn from(er: ExceptionResponse) -> Self
Converts to this type from the input type.
Source§impl From<Response> for ModbusError
impl From<Response> for ModbusError
Source§fn from(rsp: Response) -> Self
fn from(rsp: Response) -> Self
Convert a Response to a ModbusError.
Response::Exception→ModbusError::Exception- Everything else →
ModbusError::Protocol(unexpected success response in an error context — preferunexpected_responsefor direct handling inModbusClientdefault methods)
Source§impl From<String> for ModbusError
impl From<String> for ModbusError
Source§impl PartialEq for ModbusError
impl PartialEq for ModbusError
impl StructuralPartialEq for ModbusError
Auto Trait Implementations§
impl Freeze for ModbusError
impl RefUnwindSafe for ModbusError
impl Send for ModbusError
impl Sync for ModbusError
impl Unpin for ModbusError
impl UnsafeUnpin for ModbusError
impl UnwindSafe for ModbusError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more