From 226c1ced97e882000de60db5cb72b34d2961107d Mon Sep 17 00:00:00 2001 From: lumi Date: Tue, 21 Feb 2017 18:18:16 +0100 Subject: [PATCH] add a bit of documentation to the transport module --- src/transport.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/transport.rs b/src/transport.rs index f0506564..d0e9242f 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,3 +1,5 @@ +//! Provides transports for the xml streams. + use std::io::prelude::*; use std::net::TcpStream; @@ -17,16 +19,25 @@ use error::Error; use openssl::ssl::{SslMethod, SslConnectorBuilder, SslStream}; +/// A trait which transports are required to implement. pub trait Transport { + /// Writes an `xml::writer::XmlEvent` to the stream. fn write_event<'a, E: Into>>(&mut self, event: E) -> Result<(), Error>; + + /// Reads an `xml::reader::XmlEvent` from the stream. fn read_event(&mut self) -> Result; + /// Writes a `minidom::Element` to the stream. fn write_element(&mut self, element: &minidom::Element) -> Result<(), Error>; + + /// Reads a `minidom::Element` from the stream. fn read_element(&mut self) -> Result; + /// Resets the stream. fn reset_stream(&mut self); } +/// A transport which uses STARTTLS. pub struct SslTransport { inner: Arc>>, // TODO: this feels rather ugly reader: EventReader>>, // TODO: especially feels ugly because @@ -65,6 +76,7 @@ impl Transport for SslTransport { } impl SslTransport { + /// Connects to a server using STARTTLS. pub fn connect(host: &str, port: u16) -> Result { // TODO: very quick and dirty, blame starttls let mut stream = TcpStream::connect((host, port))?; @@ -106,6 +118,7 @@ impl SslTransport { }) } + /// Closes the stream. pub fn close(&mut self) { self.inner.lock() .unwrap()