xmlstream: make sink implementation generic

This allows to use any serialisable type. The advantage is that moves
and clones are avoided (which would otherwise be needed to construct
e.g. a XmppStreamElement from a Stanza or Message).
This commit is contained in:
Jonas Schäfer 2024-09-02 17:27:23 +02:00
commit c6f928d5c8
6 changed files with 62 additions and 34 deletions

View file

@ -5,7 +5,7 @@ use crate::{
client::{login::client_login, stream::ClientState},
connect::ServerConnector,
error::Error,
xmlstream::Timeouts,
xmlstream::{Timeouts, XmppStream, XmppStreamElement},
Stanza,
};
@ -75,7 +75,9 @@ impl<C: ServerConnector> Client<C> {
/// Make sure to disable reconnect.
pub async fn send_end(&mut self) -> Result<(), Error> {
match self.state {
ClientState::Connected { ref mut stream, .. } => Ok(stream.close().await?),
ClientState::Connected { ref mut stream, .. } => {
Ok(<XmppStream<C::Stream> as SinkExt<&XmppStreamElement>>::close(stream).await?)
}
ClientState::Connecting { .. } => {
self.state = ClientState::Disconnected;
Ok(())