pub struct DispatchTable { /* private fields */ }Expand description
A mapping from function code bytes to boxed FunctionCodeHandlers.
Implementations§
Source§impl DispatchTable
impl DispatchTable
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a dispatch table pre-loaded with echo handlers for all nine standard function codes.
Sourcepub fn register(&mut self, handler: Box<dyn FunctionCodeHandler>)
pub fn register(&mut self, handler: Box<dyn FunctionCodeHandler>)
Register (or replace) a handler.
Sourcepub fn dispatch(&self, req: &FunctionCodeRequest) -> FunctionCodeResponse
pub fn dispatch(&self, req: &FunctionCodeRequest) -> FunctionCodeResponse
Dispatch a request to its registered handler.
If no handler is registered for req.code, an error response with
Modbus exception code 0x01 (Illegal Function) is returned.
Sourcepub fn supported_codes(&self) -> Vec<u8> ⓘ
pub fn supported_codes(&self) -> Vec<u8> ⓘ
Return a sorted list of all supported function code bytes.
Sourcepub fn is_supported(&self, code: u8) -> bool
pub fn is_supported(&self, code: u8) -> bool
true if a handler is registered for code.
Sourcepub fn handler_count(&self) -> usize
pub fn handler_count(&self) -> usize
Number of registered handlers.
Sourcepub fn error_response(
req: &FunctionCodeRequest,
error_code: u8,
) -> FunctionCodeResponse
pub fn error_response( req: &FunctionCodeRequest, error_code: u8, ) -> FunctionCodeResponse
Build an error response: function code byte has bit 7 set, and the
data contains the single error_code byte.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DispatchTable
impl !RefUnwindSafe for DispatchTable
impl Send for DispatchTable
impl Sync for DispatchTable
impl Unpin for DispatchTable
impl UnsafeUnpin for DispatchTable
impl !UnwindSafe for DispatchTable
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more