Improving documentation

This commit is contained in:
Alexis Mousset
2014-11-10 21:37:43 +01:00
parent 809ecbbd07
commit 226fae7248
5 changed files with 20 additions and 17 deletions

View File

@@ -160,7 +160,7 @@ impl<S: Connecter + ClientStream + Clone> Client<S> {
/// * If `message` is `None`, the given command will be formatted and sent to the server
/// * If `message` is `Some(str)`, the `str` string will be sent to the server
fn send_server(&mut self, command: Command, message: Option<&str>) -> SmtpResult {
if !self.state.is_command_possible(command.clone()) {
if !self.state.is_command_allowed(command.clone()) {
fail_with_err!(Response{code: 503, message: Some("Bad sequence of commands".to_string())} self);
}

View File

@@ -32,7 +32,7 @@ pub trait ClientStream {
}
impl ClientStream for TcpStream {
/// Sends a string to the server and get the response
/// Sends a string to the server and gets the response
fn send_and_get_response(&mut self, string: &str, end: &str) -> SmtpResult {
try!(self.write_str(format!("{}{}", escape_dot(string), end).as_slice()));

View File

@@ -33,9 +33,9 @@ pub enum Command {
ExtendedHello(String),
/// Hello command
Hello(String),
/// Mail command, takes optionnal options
/// Mail command, takes optional options
Mail(String, Option<Vec<String>>),
/// Recipient command, takes optionnal options
/// Recipient command, takes optional options
Recipient(String, Option<Vec<String>>),
/// Data command
Data,
@@ -43,11 +43,11 @@ pub enum Command {
Message,
/// Reset command
Reset,
/// Verify command, takes optionnal options
/// Verify command, takes optional options
Verify(String),
/// Expand command, takes optionnal options
/// Expand command, takes optional options
Expand(String),
/// Help command, takes optionnal options
/// Help command, takes optional options
Help(Option<String>),
/// Noop command
Noop,

View File

@@ -18,12 +18,12 @@ use common::remove_trailing_crlf;
/// Contains an SMTP reply, with separed code and message
///
/// We do accept messages containing only a code, to comply with RFC5321
/// The text message is optional, only the code is mandatory
#[deriving(PartialEq,Eq,Clone)]
pub struct Response {
/// Server response code
pub code: u16,
/// Server response string (optionnal)
/// Server response string (optional)
pub message: Option<String>
}

View File

@@ -54,8 +54,9 @@ impl TransactionState {
pub fn new() -> TransactionState {
Unconnected
}
/// TODO
pub fn is_command_possible(&self, command: Command) -> bool {
/// Tests if the given command is allowed in the current state
pub fn is_command_allowed(&self, command: Command) -> bool {
match (*self, command) {
(Unconnected, command::Connect) => true,
(Unconnected, _) => false,
@@ -81,7 +82,9 @@ impl TransactionState {
}
}
/// TODO
/// Returns the state resulting of the given command
///
/// A `None` return value means the comand is not allowed.
pub fn next_state(&mut self, command: Command) -> Option<TransactionState> {
match (*self, command) {
(Unconnected, command::Connect) => Some(Connected),
@@ -120,11 +123,11 @@ mod test {
}
#[test]
fn test_is_command_possible() {
assert!(!super::Unconnected.is_command_possible(command::Noop));
assert!(!super::DataSent.is_command_possible(command::Noop));
assert!(super::HelloSent.is_command_possible(command::Mail("".to_string(), None)));
assert!(!super::MailSent.is_command_possible(command::Mail("".to_string(), None)));
fn test_is_command_allowed() {
assert!(!super::Unconnected.is_command_allowed(command::Noop));
assert!(!super::DataSent.is_command_allowed(command::Noop));
assert!(super::HelloSent.is_command_allowed(command::Mail("".to_string(), None)));
assert!(!super::MailSent.is_command_allowed(command::Mail("".to_string(), None)));
}
#[test]