pub struct WriteConnection<Write: WriteHalf> { /* private fields */ }
Expand description
A connection.
The low-level API to send messages.
§Cancel safety
All async methods of this type are cancel safe unless explicitly stated otherwise in its documentation.
Implementations§
Source§impl<Write: WriteHalf> WriteConnection<Write>
impl<Write: WriteHalf> WriteConnection<Write>
Sourcepub async fn send_call<Method>(&mut self, call: &Call<Method>) -> Result<()>
pub async fn send_call<Method>(&mut self, call: &Call<Method>) -> Result<()>
Sends a method call.
The generic Method
is the type of the method name and its input parameters. This should be
a type that can serialize itself to a complete method call message, i-e an object containing
method
and parameter
fields. This can be easily achieved using the serde::Serialize
derive:
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "method", content = "parameters")]
enum MyMethods<'m> {
// The name needs to be the fully-qualified name of the error.
#[serde(rename = "org.example.ftl.Alpha")]
Alpha { param1: u32, param2: &'m str},
#[serde(rename = "org.example.ftl.Bravo")]
Bravo,
#[serde(rename = "org.example.ftl.Charlie")]
Charlie { param1: &'m str },
}
Sourcepub async fn send_reply<Params>(&mut self, reply: &Reply<Params>) -> Result<()>
pub async fn send_reply<Params>(&mut self, reply: &Reply<Params>) -> Result<()>
Send a reply over the socket.
The generic parameter Params
is the type of the successful reply. This should be a type
that can serialize itself as the parameters
field of the reply.
Sourcepub async fn send_error<ReplyError>(&mut self, error: &ReplyError) -> Result<()>
pub async fn send_error<ReplyError>(&mut self, error: &ReplyError) -> Result<()>
Send an error reply over the socket.
The generic parameter ReplyError
is the type of the error reply. This should be a type
that can serialize itself to the whole reply object, containing error
and parameter
fields. This can be easily achieved using the serde::Serialize
derive (See the code
snippet in super::ReadConnection::receive_reply
documentation for an example).