pub struct InMemoryStore { /* private fields */ }Expand description
In-memory data store using flat tables with RwLock protection.
Implementations§
Source§impl InMemoryStore
impl InMemoryStore
Sourcepub fn new(config: StoreConfig) -> Self
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.
Sourcepub fn try_new(config: StoreConfig) -> Result<Self, StoreError>
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.
Sourcepub fn set_input_register(
&self,
address: u16,
value: u16,
) -> Result<(), StoreError>
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.
Sourcepub fn set_discrete_input(
&self,
address: u16,
value: bool,
) -> Result<(), StoreError>
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.
Sourcepub fn set_holding_register(
&self,
address: u16,
value: u16,
) -> Result<(), StoreError>
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.
Sourcepub fn set_coil(&self, address: u16, value: bool) -> Result<(), StoreError>
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.
Sourcepub fn set_file_record(
&self,
file_number: u16,
record_number: u16,
value: u16,
) -> Result<(), StoreError>
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.
Sourcepub fn set_fifo_queue(&self, address: u16, values: Vec<u16>)
pub fn set_fifo_queue(&self, address: u16, values: Vec<u16>)
Seed a FIFO queue at address with values (for test/app setup).
Sourcepub fn set_exception_status(&self, status: u8)
pub fn set_exception_status(&self, status: u8)
Set the eight exception-status coils (FC 0x07) as one packed byte.
Sourcepub fn set_server_id(&self, data: Vec<u8>)
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
impl DataStore for InMemoryStore
Source§async fn read_coils(
&self,
address: u16,
quantity: u16,
buf: &mut [bool],
) -> Result<usize, ExceptionCode>
async fn read_coils( &self, address: u16, quantity: u16, buf: &mut [bool], ) -> Result<usize, ExceptionCode>
buf. Returns number of coils written. Read moreSource§async fn read_coils_packed(
&self,
address: u16,
quantity: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_coils_packed( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn write_coil(
&self,
address: u16,
value: bool,
) -> Result<(), ExceptionCode>
async fn write_coil( &self, address: u16, value: bool, ) -> Result<(), ExceptionCode>
Source§async fn write_coils(
&self,
address: u16,
values: &[bool],
) -> Result<(), ExceptionCode>
async fn write_coils( &self, address: u16, values: &[bool], ) -> Result<(), ExceptionCode>
Source§async fn write_coils_packed(
&self,
address: u16,
quantity: u16,
packed_values: &[u8],
) -> Result<(), ExceptionCode>
async fn write_coils_packed( &self, address: u16, quantity: u16, packed_values: &[u8], ) -> Result<(), ExceptionCode>
Source§async fn read_discrete_inputs(
&self,
address: u16,
quantity: u16,
buf: &mut [bool],
) -> Result<usize, ExceptionCode>
async fn read_discrete_inputs( &self, address: u16, quantity: u16, buf: &mut [bool], ) -> Result<usize, ExceptionCode>
buf.Source§async fn read_discrete_inputs_packed(
&self,
address: u16,
quantity: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_discrete_inputs_packed( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn read_holding_registers(
&self,
address: u16,
quantity: u16,
buf: &mut [u16],
) -> Result<usize, ExceptionCode>
async fn read_holding_registers( &self, address: u16, quantity: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>
buf. Returns number of registers written.Source§async fn read_holding_registers_be(
&self,
address: u16,
quantity: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_holding_registers_be( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn write_register(
&self,
address: u16,
value: u16,
) -> Result<(), ExceptionCode>
async fn write_register( &self, address: u16, value: u16, ) -> Result<(), ExceptionCode>
Source§async fn write_registers(
&self,
address: u16,
values: &[u16],
) -> Result<(), ExceptionCode>
async fn write_registers( &self, address: u16, values: &[u16], ) -> Result<(), ExceptionCode>
Source§async fn write_registers_be(
&self,
address: u16,
quantity: u16,
value_bytes: &[u8],
) -> Result<(), ExceptionCode>
async fn write_registers_be( &self, address: u16, quantity: u16, value_bytes: &[u8], ) -> Result<(), ExceptionCode>
Source§async fn read_input_registers(
&self,
address: u16,
quantity: u16,
buf: &mut [u16],
) -> Result<usize, ExceptionCode>
async fn read_input_registers( &self, address: u16, quantity: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>
buf.Source§async fn read_input_registers_be(
&self,
address: u16,
quantity: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_input_registers_be( &self, address: u16, quantity: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn read_file_record(
&self,
file_number: u16,
record_number: u16,
record_length: u16,
buf: &mut [u16],
) -> Result<usize, ExceptionCode>
async fn read_file_record( &self, file_number: u16, record_number: u16, record_length: u16, buf: &mut [u16], ) -> Result<usize, ExceptionCode>
record_length registers from record_number
in file file_number) into buf; returns the number of registers
written (Spec V1.1b3 §6.14). Read moreSource§async fn read_file_record_be(
&self,
file_number: u16,
record_number: u16,
record_length: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_file_record_be( &self, file_number: u16, record_number: u16, record_length: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn write_file_record(
&self,
file_number: u16,
record_number: u16,
values: &[u16],
) -> Result<(), ExceptionCode>
async fn write_file_record( &self, file_number: u16, record_number: u16, values: &[u16], ) -> Result<(), ExceptionCode>
Source§async fn write_file_record_be(
&self,
file_number: u16,
record_number: u16,
record_length: u16,
value_bytes: &[u8],
) -> Result<(), ExceptionCode>
async fn write_file_record_be( &self, file_number: u16, record_number: u16, record_length: u16, value_bytes: &[u8], ) -> Result<(), ExceptionCode>
Source§async fn read_fifo_queue(&self, address: u16) -> Result<Vec<u16>, ExceptionCode>
async fn read_fifo_queue(&self, address: u16) -> Result<Vec<u16>, ExceptionCode>
address (at most 31 values; Spec V1.1b3 §6.18 — reading the queue MUST
NOT drain it). Read moreSource§async fn read_fifo_queue_be(
&self,
address: u16,
out: &mut [u8],
) -> Result<usize, ExceptionCode>
async fn read_fifo_queue_be( &self, address: u16, out: &mut [u8], ) -> Result<usize, ExceptionCode>
Source§async fn read_exception_status(&self) -> Result<u8, ExceptionCode>
async fn read_exception_status(&self) -> Result<u8, ExceptionCode>
ExceptionCode::IllegalFunction.Source§async fn report_server_id(&self) -> Result<Vec<u8>, ExceptionCode>
async fn report_server_id(&self) -> Result<Vec<u8>, ExceptionCode>
Source§async fn append_server_id(
&self,
out: &mut Vec<u8>,
) -> Result<usize, ExceptionCode>
async fn append_server_id( &self, out: &mut Vec<u8>, ) -> Result<usize, ExceptionCode>
out. Read moreSource§async fn append_diagnostic_response(
&self,
sub_function: DiagnosticSubFunction,
data: &[u8],
out: &mut Vec<u8>,
) -> Result<Option<usize>, ExceptionCode>
async fn append_diagnostic_response( &self, sub_function: DiagnosticSubFunction, data: &[u8], out: &mut Vec<u8>, ) -> Result<Option<usize>, ExceptionCode>
out. Read moreSource§fn get_comm_event_counter(
&self,
) -> impl Future<Output = Result<(u16, u16), ExceptionCode>> + Send
fn get_comm_event_counter( &self, ) -> impl Future<Output = Result<(u16, u16), ExceptionCode>> + Send
(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
fn get_comm_event_log( &self, ) -> impl Future<Output = Result<CommEventLog, ExceptionCode>> + Send
ExceptionCode::IllegalFunction.Source§fn append_comm_event_log(
&self,
out: &mut Vec<u8>,
) -> impl Future<Output = Result<CommEventLogMeta, ExceptionCode>> + Send
fn append_comm_event_log( &self, out: &mut Vec<u8>, ) -> impl Future<Output = Result<CommEventLogMeta, ExceptionCode>> + Send
out. Read more