Use Default trait for TransactionState
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user