microsandbox_protocol_client/request.rs
1//! Optional checked unary operations layered over the message API.
2
3use crate::{ClientError, EncodedMessage, Message, Protocol};
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// Pair a prepared protocol request with checked terminal-response decoding.
10///
11/// Application errors belong to the implementation, so they can retain an
12/// original peer error or legacy JSON response rather than flattening it into
13/// a generic transport error. Implementations borrow prepared inputs.
14pub trait Request<P: Protocol> {
15 /// Checked operation result, independent of SDK domain behavior.
16 type Response;
17 /// Application error that can also retain a local transport failure.
18 type Error: From<ClientError>;
19
20 /// Encode the prepared request without performing I/O.
21 fn message(&self) -> Result<EncodedMessage, Self::Error>;
22
23 /// Check the expected terminal response name, generation, and payload.
24 fn decode(&self, message: Message) -> Result<Self::Response, Self::Error>;
25}