// src/common/api_result.rs

/// API Result
/// Represents an API result
/// Value types include Success, Error, Failure

//Import modules
use ::rustc_serialize::{Encodable, json};
use ::common::validation::validation_result::ValidationResult;

pub enum ApiResult<T>{
    Success{
        result: T
    },
    Invalid{
        validation: ValidationResult,
        request: T
    },
    Failure{
        request: T
    }
}

pub struct JsonEncoder;
impl JsonEncoder{
    pub fn encode<T: Encodable>(api_result: &ApiResult<T>) -> String{
        match api_result{
            &ApiResult::Success{ref result} => {
                format!(r#"{{"status":"success", "data":{}}}"#, json::encode(&result).unwrap())
            },
            &ApiResult::Invalid{ref validation, ref request} => {
                format!(r#"{{"status":"invalid", "msg":"Request is invalid", "errors":{}, "request":{}}}"#, json::encode(&validation.get_errors()).unwrap(), json::encode(&request).unwrap())
            },
            &ApiResult::Failure{ref request} => {
                format!(r#"{{"status":"failure", "msg":"Fatal error occurred"}}"#)
            }
        }
    }
}

// src/common/api_result.rs

/// API Result
/// Represents an API result
/// Value types include Success, Error, Failure

//Import modules
use ::rustc_serialize::{Encodable, json};
use ::common::validation::validation_result::ValidationResult;

pub enum ApiResult<T>{
    Success{
        result: T
    },
    Error{
        result: ValidationResult,
        request: T
    }
}

pub struct JsonEncoder;
impl JsonEncoder{
    pub fn encode<T: Encodable>(api_result: &ApiResult<T>) -> String{
        match api_result{
            &ApiResult::Success{ref result} => {
                format!(r#"{{"status":"success", "data":{}}}"#, json::encode(&result).unwrap())
            },
            &ApiResult::Error{ref result, ref request} => {
                format!(r#"{{"status":"error", "msg":""}}"#)
            }
        }
    }
}

--- 
+++ 
@@ -12,8 +12,11 @@
     Success{
         result: T
     },
-    Error{
-        result: ValidationResult,
+    Invalid{
+        validation: ValidationResult,
+        request: T
+    },
+    Failure{
         request: T
     }
 }
@@ -25,8 +28,11 @@
             &ApiResult::Success{ref result} => {
                 format!(r#"{{"status":"success", "data":{}}}"#, json::encode(&result).unwrap())
             },
-            &ApiResult::Error{ref result, ref request} => {
-                format!(r#"{{"status":"error", "msg":""}}"#)
+            &ApiResult::Invalid{ref validation, ref request} => {
+                format!(r#"{{"status":"invalid", "msg":"Request is invalid", "errors":{}, "request":{}}}"#, json::encode(&validation.get_errors()).unwrap(), json::encode(&request).unwrap())
+            },
+            &ApiResult::Failure{ref request} => {
+                format!(r#"{{"status":"failure", "msg":"Fatal error occurred"}}"#)
             }
         }
     }
Add failure and invalid ApiResult types
