From bd631af6d24cd5ca2b03f58310e4ed8bfd396ed4 Mon Sep 17 00:00:00 2001 From: softprops Date: Mon, 10 Dec 2018 22:41:51 +0700 Subject: [PATCH 1/2] impl PartialEq for HandleError --- lambda-runtime/src/error.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lambda-runtime/src/error.rs b/lambda-runtime/src/error.rs index 2e00dcf4..6314722c 100644 --- a/lambda-runtime/src/error.rs +++ b/lambda-runtime/src/error.rs @@ -1,6 +1,6 @@ //! The error module defines the error types that can be returned //! by custom handlers as well as the runtime itself. -use std::{env, error::Error, fmt}; +use std::{cmp, env, error::Error, fmt}; use backtrace; use lambda_runtime_client::error; @@ -124,6 +124,12 @@ pub struct HandlerError { backtrace: Option, } +impl cmp::PartialEq for HandlerError { + fn eq(&self, other: &HandlerError) -> bool { + self.msg == other.msg + } +} + impl fmt::Display for HandlerError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.msg) @@ -169,3 +175,22 @@ impl error::RuntimeApiError for HandlerError { } } } + +#[cfg(test)] +mod tests { + use super::HandlerError; + + #[test] + fn handler_error_impls_partialeq() { + assert_eq!( + HandlerError { + msg: "test".into(), + backtrace: Default::default() + }, + HandlerError { + msg: "test".into(), + backtrace: Some(Default::default()) + } + ) + } +} From 23d79697aff65244c8e694fb0b5affd24911c9c1 Mon Sep 17 00:00:00 2001 From: softprops Date: Tue, 11 Dec 2018 19:09:35 +0900 Subject: [PATCH 2/2] document partialeq --- lambda-runtime/src/error.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lambda-runtime/src/error.rs b/lambda-runtime/src/error.rs index 6314722c..9dfec1fb 100644 --- a/lambda-runtime/src/error.rs +++ b/lambda-runtime/src/error.rs @@ -118,6 +118,9 @@ impl From for RuntimeError { /// The error type for functions that are used as the `Handler` type. New errors /// should be instantiated using the `new_error()` method of the `runtime::Context` /// object passed to the handler function. +/// +/// An implementation of `PartialEq` is provided and based it's comparison on the `msg` +/// field. #[derive(Debug, Clone)] pub struct HandlerError { msg: String,