Use Default trait for TransactionState

This commit is contained in:
Alexis Mousset
2015-02-28 19:39:47 +01:00
parent a35e691065
commit ca31d5eb69
2 changed files with 13 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
use std::ascii::AsciiExt;
use std::string::String;
use std::error::FromError;
use std::default::Default;
use std::old_io::net::tcp::TcpStream;
use std::old_io::net::ip::{SocketAddr, ToSocketAddr};
@@ -123,7 +124,7 @@ impl<S = TcpStream> Client<S> {
hello_name: "localhost".to_string(),
},
state: State {
transaction_state: TransactionState::new(),
transaction_state: Default::default(),
panic: false,
connection_reuse_count: 0,
current_message: None,
@@ -167,7 +168,7 @@ impl<S: Connecter + ClientStream + Clone = TcpStream> Client<S> {
// Reset the client state
self.stream = None;
self.state.transaction_state = TransactionState::new();
self.state.transaction_state = Default::default();
self.server_info = None;
self.state.panic = false;
self.state.connection_reuse_count = 0;

View File

@@ -9,6 +9,8 @@
//! State of an SMTP transaction
use std::default::Default;
use command::Command;
use self::TransactionState::{Unconnected, Connected, HelloSent, MailSent, RecipientSent, DataSent, AuthenticateSent};
@@ -31,12 +33,13 @@ pub enum TransactionState {
AuthenticateSent,
}
impl TransactionState {
/// Returns the initial state
pub fn new() -> TransactionState {
impl Default for TransactionState {
fn default() -> TransactionState {
Unconnected
}
}
impl TransactionState {
/// Tests if the given command is allowed in the current state
pub fn is_allowed(&self, command: &Command) -> bool {
(*self).next_state(command).is_some()
@@ -79,12 +82,15 @@ impl TransactionState {
#[cfg(test)]
mod test {
use std::default::Default;
use command::Command;
use super::TransactionState;
#[test]
fn test_new() {
assert_eq!(TransactionState::new(), TransactionState::Unconnected);
let default: TransactionState = Default::default();
assert_eq!(default, TransactionState::Unconnected);
}
#[test]