Skip to content

Commit 3b7ce41

Browse files
softpropsdavidbarsky
authored andcommitted
impl PartialEq for HandlerError (#43)
* impl PartialEq for HandleError * document partialeq
1 parent 090d0f0 commit 3b7ce41

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lambda-runtime/src/error.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The error module defines the error types that can be returned
22
//! by custom handlers as well as the runtime itself.
3-
use std::{env, error::Error, fmt};
3+
use std::{cmp, env, error::Error, fmt};
44

55
use backtrace;
66
use lambda_runtime_client::error;
@@ -118,12 +118,21 @@ impl From<error::ApiError> for RuntimeError {
118118
/// The error type for functions that are used as the `Handler` type. New errors
119119
/// should be instantiated using the `new_error()` method of the `runtime::Context`
120120
/// object passed to the handler function.
121+
///
122+
/// An implementation of `PartialEq` is provided and based it's comparison on the `msg`
123+
/// field.
121124
#[derive(Debug, Clone)]
122125
pub struct HandlerError {
123126
msg: String,
124127
backtrace: Option<backtrace::Backtrace>,
125128
}
126129

130+
impl cmp::PartialEq for HandlerError {
131+
fn eq(&self, other: &HandlerError) -> bool {
132+
self.msg == other.msg
133+
}
134+
}
135+
127136
impl fmt::Display for HandlerError {
128137
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129138
write!(f, "{}", self.msg)
@@ -169,3 +178,22 @@ impl error::RuntimeApiError for HandlerError {
169178
}
170179
}
171180
}
181+
182+
#[cfg(test)]
183+
mod tests {
184+
use super::HandlerError;
185+
186+
#[test]
187+
fn handler_error_impls_partialeq() {
188+
assert_eq!(
189+
HandlerError {
190+
msg: "test".into(),
191+
backtrace: Default::default()
192+
},
193+
HandlerError {
194+
msg: "test".into(),
195+
backtrace: Some(Default::default())
196+
}
197+
)
198+
}
199+
}

0 commit comments

Comments
 (0)