document Client

This commit is contained in:
lumi 2017-02-21 13:58:24 +01:00
parent 9abfa5f170
commit e6eb65e6c6

View file

@ -61,6 +61,7 @@ impl ClientBuilder {
} }
} }
/// An XMPP client.
pub struct Client { pub struct Client {
jid: Jid, jid: Jid,
transport: SslTransport, transport: SslTransport,
@ -71,15 +72,18 @@ pub struct Client {
} }
impl Client { impl Client {
/// Return a reference to the `Jid` associated with this `Client`.
pub fn jid(&self) -> &Jid { pub fn jid(&self) -> &Jid {
&self.jid &self.jid
} }
/// Register a plugin.
pub fn register_plugin<P: Plugin + 'static>(&mut self, mut plugin: P) { pub fn register_plugin<P: Plugin + 'static>(&mut self, mut plugin: P) {
plugin.bind(self.binding.clone()); plugin.bind(self.binding.clone());
self.plugins.push(Box::new(plugin)); self.plugins.push(Box::new(plugin));
} }
/// Return the plugin given by the type parameter, if it exists, else panic.
pub fn plugin<P: Plugin>(&self) -> &P { pub fn plugin<P: Plugin>(&self) -> &P {
for plugin in &self.plugins { for plugin in &self.plugins {
let any = plugin.as_any(); let any = plugin.as_any();
@ -90,6 +94,7 @@ impl Client {
panic!("plugin does not exist!"); panic!("plugin does not exist!");
} }
/// Return the next event and flush the send queue.
pub fn next_event(&mut self) -> Result<AbstractEvent, Error> { pub fn next_event(&mut self) -> Result<AbstractEvent, Error> {
self.flush_send_queue()?; self.flush_send_queue()?;
loop { loop {
@ -105,6 +110,7 @@ impl Client {
} }
} }
/// Flush the send queue, sending all queued up stanzas.
pub fn flush_send_queue(&mut self) -> Result<(), Error> { // TODO: not sure how great of an pub fn flush_send_queue(&mut self) -> Result<(), Error> { // TODO: not sure how great of an
// idea it is to flush in this // idea it is to flush in this
// manner… // manner…
@ -114,6 +120,7 @@ impl Client {
Ok(()) Ok(())
} }
/// Connect using SASL plain authentication.
pub fn connect_plain(&mut self, password: &str) -> Result<(), Error> { pub fn connect_plain(&mut self, password: &str) -> Result<(), Error> {
// TODO: this is very ugly // TODO: this is very ugly
loop { loop {