pub struct Context<RxStreamT, TxStreamT> { /* private fields */ }Expand description
Client context. Responsible for socket management and direct communication with the broker.
Implementations§
source§impl<RxStreamT, TxStreamT> Context<RxStreamT, TxStreamT>where
RxStreamT: AsyncRead + Unpin,
TxStreamT: AsyncWrite + Unpin,
impl<RxStreamT, TxStreamT> Context<RxStreamT, TxStreamT>where
RxStreamT: AsyncRead + Unpin,
TxStreamT: AsyncWrite + Unpin,
sourcepub fn new() -> (Self, ContextHandle)
pub fn new() -> (Self, ContextHandle)
Creates a new Context instance, paired with ContextHandle.
sourcepub fn set_up(&mut self, (rx, tx): (RxStreamT, TxStreamT)) -> &mut Self
pub fn set_up(&mut self, (rx, tx): (RxStreamT, TxStreamT)) -> &mut Self
Sets up communication primitives for the context. This is the first method to call when starting the connection with the broker.
Arguments
rx- Read half of the stream, must be [AsyncRead] + Unpin.tx- Write half of the stream, must be [AsyncWrite] + Unpin.
Note
Calling any other member function before prior call to set_up will panic.
sourcepub async fn connect<'a>(
&mut self,
opts: ConnectOpts<'a>
) -> Result<Either<ConnectRsp, AuthRsp>, MqttError>
pub async fn connect<'a>(
&mut self,
opts: ConnectOpts<'a>
) -> Result<Either<ConnectRsp, AuthRsp>, MqttError>
Performs connection with the broker on the protocol level. Calling this method corresponds to sending the Connect packet.
If authentication_method and authentication_data are
set in opts, the extended authorization is performed, the result of calling this method
is then AuthRsp. Otherwise, the return type is ConnectRsp.
When the reason in the CONNACK packet is greater or equal 0x80, the ConnectError is returned.
When in extended authorization mode, the authorize method is used for subsequent authorization requests.
Panics
When invoked without prior call to set_up.
Performs extended authorization between the client and the broker. It corresponds to sending the Auth packet. User may perform multiple calls of this method, as needed, until the ConnectRsp is returned, meaning the authorization is successful.
When the reason in the AUTH packet is greater or equal 0x80, the AuthError is returned.
Panics
When invoked without prior call to set_up.
sourcepub async fn run(&mut self) -> Result<(), MqttError>where
RxStreamT: AsyncRead + Unpin,
TxStreamT: AsyncWrite + Unpin,
pub async fn run(&mut self) -> Result<(), MqttError>where
RxStreamT: AsyncRead + Unpin,
TxStreamT: AsyncWrite + Unpin,
Starts processing MQTT traffic, blocking (on .await) the current task until graceful disconnection or error. Successful disconnection via disconnect method or receiving a Disconnect packet with reason a code equal to 0 (success) is considered a graceful disconnection.
Panics
When invoked without prior call to set_up.