diff options
Diffstat (limited to '')
-rw-r--r-- | src/client.rs | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/src/client.rs b/src/client.rs index 5351b34..e94008d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -44,6 +44,8 @@ impl JabberClient { pub async fn connect(&mut self) -> Result<()> { match &self.connection { ConnectionState::Disconnected => { + // TODO: actually set the self.connection as it is connecting, make more asynchronous (mutex while connecting?) + // perhaps use take_mut? self.connection = ConnectionState::Disconnected .connect(&mut self.jid, self.password.clone(), &mut self.server) .await?; @@ -53,6 +55,16 @@ impl JabberClient { ConnectionState::Connected(_jabber_stream) => Ok(()), } } + + pub async fn send_stanza(&mut self, stanza: &Stanza) -> Result<()> { + match &mut self.connection { + ConnectionState::Disconnected => return Err(Error::Disconnected), + ConnectionState::Connecting(_connecting) => return Err(Error::Connecting), + ConnectionState::Connected(jabber_stream) => { + Ok(jabber_stream.send_stanza(stanza).await?) + } + } + } } impl Stream for JabberClient { @@ -217,38 +229,6 @@ pub enum InsecureConnecting { Bound(JabberStream<Tls>), } -impl Sink<Stanza> for JabberClient { - type Error = Error; - - fn poll_ready( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll<std::result::Result<(), Self::Error>> { - todo!() - } - - fn start_send( - self: std::pin::Pin<&mut Self>, - item: Stanza, - ) -> std::result::Result<(), Self::Error> { - todo!() - } - - fn poll_flush( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll<std::result::Result<(), Self::Error>> { - todo!() - } - - fn poll_close( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll<std::result::Result<(), Self::Error>> { - todo!() - } -} - #[cfg(test)] mod tests { use std::time::Duration; |