mutant_client/
request.rs

1use mutant_protocol::Request;
2
3use crate::{error::ClientError, MutantClient};
4
5impl MutantClient {
6    /// Sends a request over the WebSocket.
7    pub async fn send_request(&mut self, request: Request) -> Result<(), ClientError> {
8        let sender = self
9            .sender
10            .as_mut()
11            .ok_or_else(|| ClientError::NotConnected)?;
12
13        let json =
14            serde_json::to_string(&request).map_err(|e| ClientError::SerializationError(e))?;
15
16        sender.send(ewebsock::WsMessage::Text(json));
17
18        Ok(())
19    }
20}