Trait GetResponseFromSimulatorTrait

Source
pub trait GetResponseFromSimulatorTrait {
    // Provided method
    fn get_response_from_simulator(
        requester: String,
        tx_to_tcp: &mut AquaSender<InternalCommand>,
        rx_from_tcp: &mut AquaReceiver<Result<f32, TcpCommunicationError>>,
        internal_command: InternalCommand,
    ) -> Result<f32, TcpCommunicationError> { ... }
}
Expand description

A trait that provides a generic method for communicating with a simulator.

Provided Methods§

Source

fn get_response_from_simulator( requester: String, tx_to_tcp: &mut AquaSender<InternalCommand>, rx_from_tcp: &mut AquaReceiver<Result<f32, TcpCommunicationError>>, internal_command: InternalCommand, ) -> Result<f32, TcpCommunicationError>

Sends a request to a simulator via a channel and blocks until a response is received.

This function standardizes the request/response pattern for fetching simulated sensor data. It sends an InternalCommand to a simulator thread (typically the TcpCommunication module) and waits for a floating-point value in return.

§Arguments
  • requester - A String identifying the calling module, used for logging and error context.
  • tx_to_tcp - The sender end of the channel to the simulator thread.
  • rx_from_tcp - The receiver end of the channel from the simulator thread.
  • internal_command - The command to send, which should be a RequestSignal variant.
§Returns

A Result containing the simulated sensor value:

  • Ok(f32): The floating-point value received from the simulator.
  • Ok(0.0): If a non-RequestSignal command is passed, which is logged and ignored.
§Errors

Returns a TcpCommunicationError if the communication fails at any stage:

  • TcpCommunicationError::SendingToTCPThreadFailed: If sending the request fails, which typically means the simulator thread has panicked or shut down and the channel is disconnected.
  • TcpCommunicationError::ReceivingFromTCPThreadFailed: If receiving the response fails, which also indicates the simulator thread is no longer available.
  • It will also propagate any TcpCommunicationError that the simulator thread itself sends back within its Result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§