Skip to main content

InMemoryStore

Struct InMemoryStore 

Source
pub struct InMemoryStore { /* private fields */ }
Expand description

In-memory data store using flat tables with RwLock protection.

Implementations§

Source§

impl InMemoryStore

Source

pub fn new(config: StoreConfig) -> Self

Create a new in-memory store with the given address space sizes.

§Panics

Panics if any table size exceeds the 16-bit Modbus address space. Use Self::try_new to handle invalid configuration without panicking.

Source

pub fn try_new(config: StoreConfig) -> Result<Self, StoreError>

Create a new in-memory store with checked address-space sizes.

§Errors

Returns StoreError::TableTooLarge if any table size exceeds 65,536.

Source

pub fn set_input_register( &self, address: u16, value: u16, ) -> Result<(), StoreError>

Direct write to an input register (for application-level updates).

§Errors

Returns StoreError::AddressOutOfRange if address is outside the configured input-register table.

Source

pub fn set_discrete_input( &self, address: u16, value: bool, ) -> Result<(), StoreError>

Direct write to a discrete input (for application-level updates).

§Errors

Returns StoreError::AddressOutOfRange if address is outside the configured discrete-input table.

Source

pub fn set_holding_register( &self, address: u16, value: u16, ) -> Result<(), StoreError>

Direct write to a holding register (for test setup).

§Errors

Returns StoreError::AddressOutOfRange if address is outside the configured holding-register table.

Source

pub fn set_coil(&self, address: u16, value: bool) -> Result<(), StoreError>

Direct write to a coil (for test setup).

§Errors

Returns StoreError::AddressOutOfRange if address is outside the configured coil table.

Source

pub fn set_file_record( &self, file_number: u16, record_number: u16, value: u16, ) -> Result<(), StoreError>

Seed a single file-record register (for test/app setup). The file and record grow lazily so sparse records can be set in any order.

§Errors

Returns StoreError if the file or record number is outside the Modbus file-record address space.

Source

pub fn set_fifo_queue(&self, address: u16, values: Vec<u16>)

Seed a FIFO queue at address with values (for test/app setup).

Source

pub fn set_exception_status(&self, status: u8)

Set the eight exception-status coils (FC 0x07) as one packed byte.

Source

pub fn set_server_id(&self, data: Vec<u8>)

Set the device-specific server-identification blob (FC 0x11).

Trait Implementations§

Source§

impl DataStore for InMemoryStore

Source§

async fn read_coils( &self, address: u16, quantity: u16, buf: &mut [bool], ) -> Result<usize, ExceptionCode>

Read coil statuses into buf. Returns number of coils written. Read more
Source§

async fn read_coils_packed( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read coil statuses directly into the Modbus packed-bit wire format. Read more
Source§

async fn write_coil( &self, address: u16, value: bool, ) -> Result<(), ExceptionCode>

Write a single coil.
Source§

async fn write_coils( &self, address: u16, values: &[bool], ) -> Result<(), ExceptionCode>

Write multiple coils.
Source§

async fn write_coils_packed( &self, address: u16, quantity: u16, packed_values: &[u8], ) -> Result<(), ExceptionCode>

Write multiple coils from the Modbus packed-bit wire representation. Read more
Source§

async fn read_discrete_inputs( &self, address: u16, quantity: u16, buf: &mut [bool], ) -> Result<usize, ExceptionCode>

Read discrete input statuses into buf.
Source§

async fn read_discrete_inputs_packed( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read discrete input statuses directly into the Modbus packed-bit wire format. Read more
Source§

async fn read_holding_registers( &self, address: u16, quantity: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>

Read holding registers into buf. Returns number of registers written.
Source§

async fn read_holding_registers_be( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read holding registers directly into big-endian Modbus wire bytes. Read more
Source§

async fn write_register( &self, address: u16, value: u16, ) -> Result<(), ExceptionCode>

Write a single holding register.
Source§

async fn write_registers( &self, address: u16, values: &[u16], ) -> Result<(), ExceptionCode>

Write multiple holding registers.
Source§

async fn write_registers_be( &self, address: u16, quantity: u16, value_bytes: &[u8], ) -> Result<(), ExceptionCode>

Write multiple holding registers from big-endian Modbus wire bytes. Read more
Source§

async fn read_input_registers( &self, address: u16, quantity: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>

Read input registers into buf.
Source§

async fn read_input_registers_be( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read input registers directly into big-endian Modbus wire bytes. Read more
Source§

async fn read_file_record( &self, file_number: u16, record_number: u16, record_length: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>

Read one file sub-record (record_length registers from record_number in file file_number) into buf; returns the number of registers written (Spec V1.1b3 §6.14). Read more
Source§

async fn read_file_record_be( &self, file_number: u16, record_number: u16, record_length: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read one file sub-record directly into big-endian Modbus wire bytes. Read more
Source§

async fn write_file_record( &self, file_number: u16, record_number: u16, values: &[u16], ) -> Result<(), ExceptionCode>

Write values to record_number in file file_number (Spec V1.1b3 §6.15). Read more
Source§

async fn write_file_record_be( &self, file_number: u16, record_number: u16, record_length: u16, value_bytes: &[u8], ) -> Result<(), ExceptionCode>

Write one file sub-record from big-endian Modbus wire bytes. Read more
Source§

async fn read_fifo_queue(&self, address: u16) -> Result<Vec<u16>, ExceptionCode>

Return a non-destructive snapshot of the FIFO queue whose pointer is at address (at most 31 values; Spec V1.1b3 §6.18 — reading the queue MUST NOT drain it). Read more
Source§

async fn read_fifo_queue_be( &self, address: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>

Read a FIFO queue snapshot directly into big-endian Modbus wire bytes. Read more
Source§

async fn read_exception_status(&self) -> Result<u8, ExceptionCode>

Read the eight device-specific exception-status coils as one byte (FC 0x07, §6.7). The default returns ExceptionCode::IllegalFunction.
Source§

async fn report_server_id(&self) -> Result<Vec<u8>, ExceptionCode>

Report a device-specific server-identification blob (FC 0x11, §6.13). Read more
Source§

async fn append_server_id( &self, out: &mut Vec<u8>, ) -> Result<usize, ExceptionCode>

Append the FC 0x11 server-identification data bytes to out. Read more
Source§

async fn append_diagnostic_response( &self, sub_function: DiagnosticSubFunction, data: &[u8], out: &mut Vec<u8>, ) -> Result<Option<usize>, ExceptionCode>

Append Diagnostics response data bytes to out. Read more
Source§

fn get_comm_event_counter( &self, ) -> impl Future<Output = Result<(u16, u16), ExceptionCode>> + Send

Get the comm event counter as (status, event_count) (FC 0x0B, §6.9). The default returns ExceptionCode::IllegalFunction.
Source§

fn get_comm_event_log( &self, ) -> impl Future<Output = Result<CommEventLog, ExceptionCode>> + Send

Get the communications event log (FC 0x0C, §6.10). The default returns ExceptionCode::IllegalFunction.
Source§

fn append_comm_event_log( &self, out: &mut Vec<u8>, ) -> impl Future<Output = Result<CommEventLogMeta, ExceptionCode>> + Send

Append FC 0x0C communication event bytes to out. Read more
Source§

fn diagnostic( &self, sub_function: DiagnosticSubFunction, data: &[u8], ) -> impl Future<Output = Result<Option<Vec<u8>>, ExceptionCode>> + Send

Execute a Diagnostics sub-function (FC 0x08, §6.8). Read more
Source§

impl Debug for InMemoryStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more