diff --git a/src/client/mod.rs b/src/client/mod.rs index e33b4a5..cc160e7 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -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 Client { 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 Client { // 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; diff --git a/src/transaction.rs b/src/transaction.rs index a32ca85..6ca2492 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -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]