Struct lambda_runtime::Diagnostic
source · pub struct Diagnostic<'a> {
pub error_type: Cow<'a, str>,
pub error_message: Cow<'a, str>,
}
Expand description
Diagnostic information about an error.
Diagnostic
is automatically derived for types that implement
Display
; e.g., Error
.
error_type
is derived from the type name of
the original error with std::any::type_name
as a fallback, which may
not be reliable for conditional error handling.
You can define your own error container that implements Into<Diagnostic>
if you need to handle errors based on error types.
Example:
use lambda_runtime::{Diagnostic, Error, LambdaEvent};
use std::borrow::Cow;
#[derive(Debug)]
struct ErrorResponse(Error);
impl<'a> Into<Diagnostic<'a>> for ErrorResponse {
fn into(self) -> Diagnostic<'a> {
Diagnostic {
error_type: Cow::Borrowed("MyError"),
error_message: Cow::Owned(self.0.to_string()),
}
}
}
async fn function_handler(_event: LambdaEvent<()>) -> Result<(), ErrorResponse> {
// ... do something
Ok(())
}
Fields§
§error_type: Cow<'a, str>
Error type.
error_type
is derived from the type name of the original error with
std::any::type_name
as a fallback.
Please implement your own Into<Diagnostic>
if you need more reliable
error types.
error_message: Cow<'a, str>
Error message.
error_message
is the output from the Display
implementation of the original error as a fallback.
Trait Implementations§
source§impl<'a> Clone for Diagnostic<'a>
impl<'a> Clone for Diagnostic<'a>
source§fn clone(&self) -> Diagnostic<'a>
fn clone(&self) -> Diagnostic<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for Diagnostic<'a>
impl<'a> Debug for Diagnostic<'a>
source§impl<'de, 'a> Deserialize<'de> for Diagnostic<'a>
impl<'de, 'a> Deserialize<'de> for Diagnostic<'a>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'a, T> From<T> for Diagnostic<'a>where
T: Display,
impl<'a, T> From<T> for Diagnostic<'a>where
T: Display,
source§impl<'a> PartialEq for Diagnostic<'a>
impl<'a> PartialEq for Diagnostic<'a>
source§fn eq(&self, other: &Diagnostic<'a>) -> bool
fn eq(&self, other: &Diagnostic<'a>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<'a> Serialize for Diagnostic<'a>
impl<'a> Serialize for Diagnostic<'a>
impl<'a> Eq for Diagnostic<'a>
impl<'a> StructuralPartialEq for Diagnostic<'a>
Auto Trait Implementations§
impl<'a> Freeze for Diagnostic<'a>
impl<'a> RefUnwindSafe for Diagnostic<'a>
impl<'a> Send for Diagnostic<'a>
impl<'a> Sync for Diagnostic<'a>
impl<'a> Unpin for Diagnostic<'a>
impl<'a> UnwindSafe for Diagnostic<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<B> IntoFunctionResponse<B, Body> for Bwhere
B: Serialize,
impl<B> IntoFunctionResponse<B, Body> for Bwhere
B: Serialize,
source§fn into_response(self) -> FunctionResponse<B, Body>
fn into_response(self) -> FunctionResponse<B, Body>
Convert the type into a FunctionResponse.